ledger

package
v0.0.0-...-261ff67 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TrieArity    = common.PathArity16
	TrieHashSize = trie_blake2b.HashSize256
)
View Source
const (
	BootstrapSequencerName = "boot"
	BoostrapSequencerIDHex = "af7bedde1fea222230b82d63d5b665ac75afbe4ad3f75999bb3386cf994a6963"
)
View Source
const (
	TransactionIDShortLength = 27
	TransactionIDLength      = TimeByteLength + TransactionIDShortLength
	OutputIDLength           = TransactionIDLength + 1
	ChainIDLength            = 32

	SequencerTxFlagHigherByte = byte(0b10000000)
)
View Source
const (
	GenesisOutputIndex     = byte(0)
	GenesisStemOutputIndex = byte(1)
)
View Source
const (
	DefaultTickDuration        = 100 * time.Millisecond
	DefaultTicksPerSlot        = 100
	DefaultSlotDuration        = DefaultTickDuration * DefaultTicksPerSlot
	DefaultSlotsPerLedgerEpoch = time.Hour * 24 * 365 / DefaultSlotDuration

	DustPerProxi         = 1_000_000
	BaseTokenName        = "Proxi"
	BaseTokenNameTicker  = "PRXI"
	DustTokenName        = "dust"
	PRXI                 = DustPerProxi
	InitialSupplyProxi   = 1_000_000_000
	DefaultInitialSupply = InitialSupplyProxi * PRXI

	DefaultMaxBranchInflationBonus              = 5 * PRXI
	DefaultInitialChainInflationFractionPerTick = 500_000_000
	DefaultHalvingEpochs                        = 5
	DefaultChainInflationOpportunitySlots       = 12
	DefaultVBCost                               = 1
	DefaultTransactionPace                      = 10
	DefaultTransactionPaceSequencer             = 1
	DefaultMinimumAmountOnSequencer             = 1_000 * PRXI
	DefaultMaxNumberOfEndorsements              = 8
)
View Source
const (
	SlotByteLength = 4
	TickByteLength = 1
	TimeByteLength = SlotByteLength + TickByteLength // bytes
	MaxSlot        = 0xffffffff >> 1                 // 1 most significant bit must be 0
)
View Source
const (
	TransactionBranch = byte(iota)
	ConsumedBranch
)

Top level branches

View Source
const (
	TxUnlockData = byte(iota)
	TxInputIDs
	TxOutputs
	TxSignature
	TxSequencerAndStemOutputIndices
	TxTimestamp
	TxTotalProducedAmount
	TxInputCommitment
	TxEndorsements
	TxLocalLibraries
	TxTreeIndexMax
)

Transaction tree

View Source
const (
	ConstraintIndexAmount = byte(iota)
	ConstraintIndexLock
	ConstraintIndexFirstOptionalConstraint
)

Mandatory output block indices

View Source
const (
	AddressED25519Name = "addressED25519"
)
View Source
const (
	AmountConstraintName = "amount"
)
View Source
const (
	ChainConstraintName = "chain"
)
View Source
const (
	ChainLockName = "chainLock"
)
View Source
const (
	CommitToSiblingName = "commitToSibling"
)
View Source
const ConditionalLockName = "conditionalLock"
View Source
const (
	ConsumedOutputsBranch = byte(iota)
)
View Source
const (
	DeadlineLockName = "deadlineLock"
)
View Source
const (
	ImmutableName = "immutable"
)
View Source
const (
	InflationConstraintName = "inflation"
)
View Source
const MilestoneDataFixedIndex = 4
View Source
const (
	RoyaltiesED25519Name = "royaltiesED25519"
)
View Source
const (
	SenderAddressED25519Name = "senderED25519"
)
View Source
const (
	SequencerConstraintName = "sequencer"
)
View Source
const (
	StateIndexName = "stateIndex"
)
View Source
const (
	StemLockName = "stemLock"
)
View Source
const (
	TimelockName = "timelock"
)
View Source
const (
	TotalAmountConstraintName = "total"
)

Variables

View Source
var All0TransactionHash = TransactionIDShort{}
View Source
var NilTimelock = Timelock(0)
View Source
var StemAccountID = AccountID([]byte{0})

Functions

func AddressED25519MatchesPrivateKey

func AddressED25519MatchesPrivateKey(addr AddressED25519, privateKey ed25519.PrivateKey) bool

func BelongsToAccount

func BelongsToAccount(lock Lock, acc Accountable) bool

func BranchInflationBonusFromRandomnessProof

func BranchInflationBonusFromRandomnessProof(data []byte) uint64

BranchInflationBonusFromRandomnessProof makes uint64 in the range from 0 to BranchBonusBase (incl)

func DiffTicks

func DiffTicks(t1, t2 Time) int64

DiffTicks returns difference in ticks between two timestamps: < 0 is t1 is before t2 > 0 if t2 is before t1 (i.e. t1 - t2)

func EqualAccountables

func EqualAccountables(a1, a2 Accountable) bool

func EqualConstraints

func EqualConstraints(l1, l2 Constraint) bool

func EqualTransactionIDs

func EqualTransactionIDs(txid1, txid2 *TransactionID) bool

func Init

func Init(id *IdentityData, verbose ...bool)

func InitWithTestingLedgerIDData

func InitWithTestingLedgerIDData(opts ...func(data *IdentityData)) ed25519.PrivateKey

InitWithTestingLedgerIDData for testing

func LessTxID

func LessTxID(txid1, txid2 TransactionID) bool

LessTxID compares tx IDs b timestamp and by tx hash

func MinimumStorageDeposit

func MinimumStorageDeposit(o *Output, extraWeight uint32) uint64

func MustOutputIndexFromIDBytes

func MustOutputIndexFromIDBytes(data []byte) byte

func NameByPrefix

func NameByPrefix(prefix []byte) (string, bool)

func NewChainLockUnlockParams

func NewChainLockUnlockParams(chainOutputIndex, chainConstraintIndex byte) []byte

func NewChainUnlockParams

func NewChainUnlockParams(successorOutputIdx, successorConstraintBlockIndex, transitionMode byte) []byte

NewChainUnlockParams unlock parameters for the chain constraint. 3 bytes: 0 - successor output index 1 - successor block index 2 - transition mode must be equal to the transition mode in the successor constraint data

func NewTransactionIDPrefix

func NewTransactionIDPrefix(slot Slot, sequencerTxFlag bool) (ret [4]byte)

NewTransactionIDPrefix used for database iteration by prefix, i.e. all transaction IDs of specific slot

func OutputFromBytesMain

func OutputFromBytesMain(data []byte) (*Output, Amount, Lock, error)

func OutputIDIndexFromBytes

func OutputIDIndexFromBytes(data []byte) (ret byte, err error)

OutputIDIndexFromBytes optimizes memory usage

func OutputsWithIdToString

func OutputsWithIdToString(outs ...*OutputWithID) string

func SleepDurationUntilFutureLedgerTime

func SleepDurationUntilFutureLedgerTime(ts Time) (ret time.Duration)

SleepDurationUntilFutureLedgerTime returns duration to sleep until the clock becomes to ts.Time()

func SlotDuration

func SlotDuration() time.Duration

func SlotsPerDay

func SlotsPerDay() time.Duration

func SlotsPerHalvingEpoch

func SlotsPerHalvingEpoch() int64

func SlotsPerHour

func SlotsPerHour() int

func TickDuration

func TickDuration() time.Duration

func TicksPerHour

func TicksPerHour() int

func TicksPerSlot

func TicksPerSlot() byte

func TicksPerYear

func TicksPerYear() int

func TooCloseOnTimeAxis

func TooCloseOnTimeAxis(txid1, txid2 *TransactionID) bool

func TransactionIDAsFileName

func TransactionIDAsFileName(ts Time, txHash TransactionIDShort, sequencerFlag, branchFlag bool) string

func TransactionIDString

func TransactionIDString(ts Time, txHash TransactionIDShort, sequencerFlag bool) string

func TransactionIDStringShort

func TransactionIDStringShort(ts Time, txHash TransactionIDShort, sequencerFlag bool) string

func TransactionIDStringVeryShort

func TransactionIDStringVeryShort(ts Time, txHash TransactionIDShort, sequencerFlag bool) string

func TransactionPace

func TransactionPace() int

func TransactionPaceSequencer

func TransactionPaceSequencer() int

func ValidSequencerPace

func ValidSequencerPace(t1, t2 Time) bool

func ValidTime

func ValidTime(ts Time) bool

func ValidTransactionPace

func ValidTransactionPace(t1, t2 Time) bool

ValidTransactionPace checks if 2 timestamps have at least time pace slots in between

func WithSequencerPace

func WithSequencerPace(ticks byte) func(id *IdentityData)

func WithTickDuration

func WithTickDuration(d time.Duration) func(id *IdentityData)

func WithTransactionPace

func WithTransactionPace(ticks byte) func(id *IdentityData)

Types

type AccountID

type AccountID []byte

func (AccountID) Bytes

func (acc AccountID) Bytes() []byte

type Accountable

type Accountable interface {
	Constraint
	AccountID() AccountID
	AsLock() Lock
}

func AccountableFromBytes

func AccountableFromBytes(data []byte) (Accountable, error)

func AccountableFromSource

func AccountableFromSource(src string) (Accountable, error)

func NoDuplicatesAccountables

func NoDuplicatesAccountables(acc []Accountable) []Accountable

type AddressED25519

type AddressED25519 []byte

func AddressED25519FromBytes

func AddressED25519FromBytes(data []byte) (AddressED25519, error)

func AddressED25519FromPrivateKey

func AddressED25519FromPrivateKey(privateKey ed25519.PrivateKey) AddressED25519

func AddressED25519FromPublicKey

func AddressED25519FromPublicKey(pubKey ed25519.PublicKey) AddressED25519

func AddressED25519FromSource

func AddressED25519FromSource(src string) (AddressED25519, error)

func AddressED25519Null

func AddressED25519Null() AddressED25519

func AddressED25519Random

func AddressED25519Random() AddressED25519

func AddressesED25519FromPrivateKeys

func AddressesED25519FromPrivateKeys(privateKeys []ed25519.PrivateKey) []AddressED25519

func (AddressED25519) AccountID

func (a AddressED25519) AccountID() AccountID

func (AddressED25519) Accounts

func (a AddressED25519) Accounts() []Accountable

func (AddressED25519) AsLock

func (a AddressED25519) AsLock() Lock

func (AddressED25519) Bytes

func (a AddressED25519) Bytes() []byte

func (AddressED25519) Clone

func (a AddressED25519) Clone() AddressED25519

func (AddressED25519) Name

func (a AddressED25519) Name() string

func (AddressED25519) Short

func (a AddressED25519) Short() string

func (AddressED25519) String

func (a AddressED25519) String() string

type Amount

type Amount uint64

func AmountFromBytes

func AmountFromBytes(data []byte) (Amount, error)

func NewAmount

func NewAmount(a uint64) Amount

func (Amount) Amount

func (a Amount) Amount() uint64

func (Amount) Bytes

func (a Amount) Bytes() []byte

func (Amount) Name

func (a Amount) Name() string

func (Amount) String

func (a Amount) String() string

type ChainConstraint

type ChainConstraint struct {
	// ID all-0 for origin
	ID ChainID
	// 0xFF for origin, 0x00 for state transition, other reserved
	TransitionMode byte
	// Previous index of the consumed chain input with the same ID. Must be 0xFF for the origin
	PredecessorInputIndex      byte
	PredecessorConstraintIndex byte
}

ChainConstraint is a chain constraint

func ChainConstraintFromBytes

func ChainConstraintFromBytes(data []byte) (*ChainConstraint, error)

func NewChainConstraint

func NewChainConstraint(id ChainID, prevOut, prevBlock, mode byte) *ChainConstraint

func NewChainOrigin

func NewChainOrigin() *ChainConstraint

func (*ChainConstraint) Bytes

func (ch *ChainConstraint) Bytes() []byte

func (*ChainConstraint) IsOrigin

func (ch *ChainConstraint) IsOrigin() bool

func (*ChainConstraint) Name

func (ch *ChainConstraint) Name() string

func (*ChainConstraint) String

func (ch *ChainConstraint) String() string

type ChainID

type ChainID [ChainIDLength]byte

ChainID all-0 for origin

var BoostrapSequencerID ChainID
var NilChainID ChainID

func ChainIDFromBytes

func ChainIDFromBytes(data []byte) (ret ChainID, err error)

func ChainIDFromHexString

func ChainIDFromHexString(str string) (ret ChainID, err error)

func MakeOriginChainID

func MakeOriginChainID(originOutputID *OutputID) ChainID

func RandomChainID

func RandomChainID() (ret ChainID)

func (*ChainID) AsAccountID

func (id *ChainID) AsAccountID() AccountID

func (*ChainID) AsChainLock

func (id *ChainID) AsChainLock() ChainLock

func (*ChainID) Bytes

func (id *ChainID) Bytes() []byte

func (*ChainID) MarshalJSON

func (id *ChainID) MarshalJSON() ([]byte, error)

func (*ChainID) String

func (id *ChainID) String() string

func (*ChainID) StringHex

func (id *ChainID) StringHex() string

func (*ChainID) StringShort

func (id *ChainID) StringShort() string

func (*ChainID) StringVeryShort

func (id *ChainID) StringVeryShort() string

func (*ChainID) UnmarshalJSON

func (id *ChainID) UnmarshalJSON(hexStrData []byte) error

type ChainLock

type ChainLock []byte

func ChainLockFromBytes

func ChainLockFromBytes(data []byte) (ChainLock, error)

func ChainLockFromChainID

func ChainLockFromChainID(chainID ChainID) ChainLock

func (ChainLock) AccountID

func (cl ChainLock) AccountID() AccountID

func (ChainLock) Accounts

func (cl ChainLock) Accounts() []Accountable

func (ChainLock) AsLock

func (cl ChainLock) AsLock() Lock

func (ChainLock) Bytes

func (cl ChainLock) Bytes() []byte

func (ChainLock) ChainID

func (cl ChainLock) ChainID() ChainID

func (ChainLock) Name

func (cl ChainLock) Name() string

func (ChainLock) String

func (cl ChainLock) String() string

type CommitToSibling

type CommitToSibling struct {
	SiblingIndex byte
	SiblingHash  []byte
}

func CommitToSiblingFromBytes

func CommitToSiblingFromBytes(data []byte) (*CommitToSibling, error)

func NewCommitToSibling

func NewCommitToSibling(siblingIndex byte, siblingHash []byte) *CommitToSibling

func (*CommitToSibling) Bytes

func (cs *CommitToSibling) Bytes() []byte

func (*CommitToSibling) Name

func (cs *CommitToSibling) Name() string

func (*CommitToSibling) String

func (cs *CommitToSibling) String() string

type ConditionalLock

type ConditionalLock struct {
	Conditions [4]Constraint
	Locks      [4]Accountable
}

ConditionalLock enforces condition by selecting first of up to 4 satisfied conditions and evaluating corresponding accountable lock

func ConditionalLockFromBytes

func ConditionalLockFromBytes(data []byte) (*ConditionalLock, error)

func NewConditionalLock

func NewConditionalLock(conds []Constraint, locks []Accountable) (*ConditionalLock, error)

func (*ConditionalLock) Accounts

func (c *ConditionalLock) Accounts() []Accountable

func (*ConditionalLock) Bytes

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

func (*ConditionalLock) Name

func (c *ConditionalLock) Name() string

func (*ConditionalLock) String

func (c *ConditionalLock) String() string

type Constraint

type Constraint interface {
	Name() string
	Bytes() []byte
	String() string
}

func ConstraintFromBytes

func ConstraintFromBytes(data []byte) (Constraint, error)

type DataContext

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

DataContext is the data structure passed to the eval call. It contains: - tree: all validation context of the transaction, all data which is to be validated - path: a path in the validation context of the constraint being validated in the eval call

func NewDataContext

func NewDataContext(tree *lazybytes.Tree) *DataContext

func (*DataContext) DataTree

func (c *DataContext) DataTree() *lazybytes.Tree

func (*DataContext) Path

func (c *DataContext) Path() lazybytes.TreePath

func (*DataContext) SetPath

func (c *DataContext) SetPath(path lazybytes.TreePath)

type DeadlineLock

type DeadlineLock struct {
	Deadline         Slot
	ConstraintMain   Accountable
	ConstraintExpiry Accountable
}

func DeadlineLockFromBytes

func DeadlineLockFromBytes(data []byte) (*DeadlineLock, error)

func NewDeadlineLock

func NewDeadlineLock(deadline Slot, main, expiry Accountable) *DeadlineLock

func (*DeadlineLock) Accounts

func (dl *DeadlineLock) Accounts() []Accountable

func (*DeadlineLock) Bytes

func (dl *DeadlineLock) Bytes() []byte

func (*DeadlineLock) Name

func (dl *DeadlineLock) Name() string

func (*DeadlineLock) String

func (dl *DeadlineLock) String() string

type GeneralScript

type GeneralScript []byte

func NewGeneralScript

func NewGeneralScript(data []byte) GeneralScript

func NewGeneralScriptFromSource

func NewGeneralScriptFromSource(src string) (GeneralScript, error)

func (GeneralScript) Bytes

func (u GeneralScript) Bytes() []byte

func (GeneralScript) Name

func (u GeneralScript) Name() string

func (GeneralScript) String

func (u GeneralScript) String() string

type IdentityData

type IdentityData struct {
	// arbitrary string up 255 bytes
	Description string
	// genesis time unix seconds
	GenesisTimeUnix uint32
	// initial supply of tokens
	InitialSupply uint64
	// ED25519 public key of the controller
	GenesisControllerPublicKey ed25519.PublicKey
	// time tick duration in nanoseconds
	TickDuration time.Duration
	// max time tick value in the slot. Up to 256 time ticks per time slot, default 100
	MaxTickValueInSlot uint8
	// ----------- inflation-related
	// NumHalvingEpochs number of halving epochs
	NumHalvingEpochs byte
	// Default 2_289_600. approx one year in slots.
	SlotsPerHalvingEpoch uint32
	// IBranchBonusBase inflation bonus
	BranchBonusBase uint64
	// ChainInflationPerTickFractionBase and HalvingYears
	ChainInflationPerTickFractionBase uint64
	// ChainInflationOpportunitySlots maximum gap between chain outputs for the non-zero inflation
	ChainInflationOpportunitySlots uint64
	// VBCost
	VBCost uint64
	// number of ticks between non-sequencer transactions
	TransactionPace byte
	// number of ticks between sequencer transactions
	TransactionPaceSequencer byte
	// this limits number of sequencers in the network. Reasonable amount would be few hundreds of sequencers
	MinimumAmountOnSequencer uint64
	// limit maximum number of endorsements. For determinism
	MaxNumberOfEndorsements uint64
}

IdentityData is provided at genesis and will remain immutable during lifetime All integers are serialized as big-endian

func DefaultIdentityData

func DefaultIdentityData(privateKey ed25519.PrivateKey) *IdentityData

func GetTestingIdentityData

func GetTestingIdentityData(seed ...int) (*IdentityData, ed25519.PrivateKey)

func MustLedgerIdentityDataFromBytes

func MustLedgerIdentityDataFromBytes(data []byte) *IdentityData

func StateIdentityDataFromYAML

func StateIdentityDataFromYAML(yamlData []byte) (*IdentityData, error)

func (*IdentityData) Bytes

func (id *IdentityData) Bytes() []byte

func (*IdentityData) ChainInflationAmount

func (id *IdentityData) ChainInflationAmount(inTs, outTs Time, inAmount uint64) uint64

ChainInflationAmount mocks inflation amount formula from the constraint library Safe arithmetics!

func (*IdentityData) GenesisControlledAddress

func (id *IdentityData) GenesisControlledAddress() AddressED25519

func (*IdentityData) GenesisTime

func (id *IdentityData) GenesisTime() time.Time

func (*IdentityData) GenesisTimeUnixNano

func (id *IdentityData) GenesisTimeUnixNano() int64

func (*IdentityData) Hash

func (id *IdentityData) Hash() [32]byte

func (*IdentityData) InflationAmount

func (id *IdentityData) InflationAmount(inTs, outTs Time, inAmount uint64) uint64

InflationAmount is calculation of inflation amount directly from ledger identity constants

func (*IdentityData) InflationFractionBySlot

func (id *IdentityData) InflationFractionBySlot(slotIn Slot) uint64

func (*IdentityData) Lines

func (id *IdentityData) Lines(prefix ...string) *lines.Lines

func (*IdentityData) OriginChainID

func (id *IdentityData) OriginChainID() ChainID

func (*IdentityData) SetTickDuration

func (id *IdentityData) SetTickDuration(d time.Duration)

func (*IdentityData) SlotDuration

func (id *IdentityData) SlotDuration() time.Duration

func (*IdentityData) SlotsPerDay

func (id *IdentityData) SlotsPerDay() int

func (*IdentityData) String

func (id *IdentityData) String() string

func (*IdentityData) TicksPerSlot

func (id *IdentityData) TicksPerSlot() int

func (*IdentityData) TimeConstantsToString

func (id *IdentityData) TimeConstantsToString() string

func (*IdentityData) TimeFromRealTime

func (id *IdentityData) TimeFromRealTime(nowis time.Time) Time

func (*IdentityData) TimeHorizonYears

func (id *IdentityData) TimeHorizonYears() int

func (*IdentityData) YAML

func (id *IdentityData) YAML() []byte

func (*IdentityData) YAMLAble

func (id *IdentityData) YAMLAble() *IdentityDataYAMLAble

type IdentityDataYAMLAble

type IdentityDataYAMLAble struct {
	GenesisTimeUnix                   uint32 `yaml:"genesis_time_unix"`
	InitialSupply                     uint64 `yaml:"initial_supply"`
	GenesisControllerPublicKey        string `yaml:"genesis_controller_public_key"`
	TimeTickDurationNanosec           int64  `yaml:"time_tick_duration_nanosec"`
	MaxTimeTickValueInTimeSlot        uint8  `yaml:"max_time_tick_value_in_time_slot"`
	BranchBonusBase                   uint64 `yaml:"branch_bonus_base"`
	SlotsPerHalvingEpoch              uint32 `yaml:"slots_per_halving_epoch"`
	VBCost                            uint64 `yaml:"vb_cost"`
	TransactionPace                   byte   `yaml:"transaction_pace"`
	TransactionPaceSequencer          byte   `yaml:"transaction_pace_sequencer"`
	NumHalvingEpochs                  byte   `yaml:"num_halving_epochs"`
	ChainInflationPerTickFractionBase uint64 `yaml:"chain_inflation_per_tick_fraction_base"`
	ChainInflationOpportunitySlots    uint64 `yaml:"chain_inflation_opportunity_slots"`
	MinimumAmountOnSequencer          uint64 `yaml:"minimum_amount_on_sequencer"`
	MaxNumberOfEndorsements           uint64 `yaml:"max_number_of_endorsements"`
	Description                       string `yaml:"description"`
	// non-persistent, for control
	GenesisControllerAddress string `yaml:"genesis_controller_address"`
	BootstrapChainID         string `yaml:"bootstrap_chain_id"`
}

IdentityDataYAMLAble structure for canonical YAMLAble marshaling

func (*IdentityDataYAMLAble) YAML

func (id *IdentityDataYAMLAble) YAML() []byte

type Immutable

type Immutable struct {
	ChainBlockIndex byte
	DataBlockIndex  byte
}

func ImmutableFromBytes

func ImmutableFromBytes(data []byte) (*Immutable, error)

func NewImmutable

func NewImmutable(chainBlockIndex, dataBlockIndex byte) *Immutable

func (*Immutable) Bytes

func (d *Immutable) Bytes() []byte

func (*Immutable) Name

func (d *Immutable) Name() string

func (*Immutable) String

func (d *Immutable) String() string

type InflationConstraint

type InflationConstraint struct {
	// must point to the sibling chain constraint
	ChainConstraintIndex byte
	AmountOrRndProof     []byte
}

func InflationConstraintFromBytes

func InflationConstraintFromBytes(data []byte) (*InflationConstraint, error)

func NewInflationConstraint

func NewInflationConstraint(chainConstraintIndex byte, amountOrRndProof []byte) *InflationConstraint

func (*InflationConstraint) Bytes

func (i *InflationConstraint) Bytes() []byte

func (*InflationConstraint) InflationAmount

func (i *InflationConstraint) InflationAmount(branch bool) uint64

InflationAmount calculates inflation amount either inside slot, or on branch

func (*InflationConstraint) Name

func (i *InflationConstraint) Name() string

func (*InflationConstraint) String

func (i *InflationConstraint) String() string

type Library

type Library struct {
	*easyfl.Library
	ID *IdentityData
	// contains filtered or unexported fields
}

func InitLocally

func InitLocally(id *IdentityData, verbose ...bool) *Library

func L

func L() *Library

func (*Library) CompileLocalLibrary

func (lib *Library) CompileLocalLibrary(source string) ([]byte, error)

CompileLocalLibrary compiles local library and serializes it as lazy array

func (*Library) Const

func (lib *Library) Const() LibraryConst

func (*Library) TimeFromRealTime

func (lib *Library) TimeFromRealTime(t time.Time) Time

type LibraryConst

type LibraryConst struct {
	*Library
}

func (LibraryConst) ChainInflationPerTickFractionBase

func (lib LibraryConst) ChainInflationPerTickFractionBase() uint64

func (LibraryConst) HalvingEpoch

func (lib LibraryConst) HalvingEpoch(ts Time) byte

func (LibraryConst) HalvingEpochs

func (lib LibraryConst) HalvingEpochs() byte

func (LibraryConst) MinimumAmountOnSequencer

func (lib LibraryConst) MinimumAmountOnSequencer() uint64

func (LibraryConst) SlotsPerEpoch

func (lib LibraryConst) SlotsPerEpoch() uint32

func (LibraryConst) TicksPerSlot

func (lib LibraryConst) TicksPerSlot() byte

type Lock

type Lock interface {
	Constraint
	Accounts() []Accountable
}

func LockFromBytes

func LockFromBytes(data []byte) (Lock, error)

type LockBalance

type LockBalance struct {
	Lock    Lock
	Balance uint64
}

type MilestoneData

type MilestoneData struct {
	Name         string // < 256
	MinimumFee   uint64
	ChainHeight  uint32
	BranchHeight uint32
}

MilestoneData data which is on sequencer as 'or(..)' constraint. It is not enforced by the ledger, yet maintained by the sequencer

func MilestoneDataFromConstraint

func MilestoneDataFromConstraint(constr []byte) (*MilestoneData, error)

func ParseMilestoneData

func ParseMilestoneData(o *Output) *MilestoneData

ParseMilestoneData expected at index 4, otherwise nil

func (*MilestoneData) AsConstraint

func (od *MilestoneData) AsConstraint() Constraint

type Output

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

func NewOutput

func NewOutput(overrideReadOnly ...func(o *Output)) *Output

func OutputBasic

func OutputBasic(amount uint64, lock Lock) *Output

func OutputFromBytesReadOnly

func OutputFromBytesReadOnly(data []byte, validateOpt ...func(*Output) error) (*Output, error)

func (*Output) AccountIDs

func (o *Output) AccountIDs() []AccountID

func (*Output) Amount

func (o *Output) Amount() uint64

func (*Output) AsArray

func (o *Output) AsArray() *lazybytes.Array

func (*Output) Bytes

func (o *Output) Bytes() []byte

func (*Output) ChainConstraint

func (o *Output) ChainConstraint() (*ChainConstraint, byte)

ChainConstraint finds and parses chain constraint. Returns its constraintIndex or 0xff if not found

func (*Output) Clone

func (o *Output) Clone(overrideReadOnly ...func(o *Output)) *Output

Clone clones output and makes it read-only. Optional function overrideReadOnly gives a chance to modify the output before it is locked for modification

func (*Output) ConstraintAt

func (o *Output) ConstraintAt(idx byte) []byte

func (*Output) ConstraintsRawBytes

func (o *Output) ConstraintsRawBytes() [][]byte

func (*Output) ForEachConstraint

func (o *Output) ForEachConstraint(fun func(idx byte, constr []byte) bool)

func (*Output) Inflation

func (o *Output) Inflation(branch bool) uint64

func (*Output) InflationConstraint

func (o *Output) InflationConstraint() (*InflationConstraint, byte)

InflationConstraint finds and parses inflation constraint. Returns its constraintIndex or 0xff if not found

func (*Output) Lines

func (o *Output) Lines(prefix ...string) *lines.Lines

func (*Output) Lock

func (o *Output) Lock() Lock

func (*Output) MustHaveConstraintAnyOfAt

func (o *Output) MustHaveConstraintAnyOfAt(pos byte, names ...string)

func (*Output) MustStemLock

func (o *Output) MustStemLock() *StemLock

func (*Output) MustValidOutput

func (o *Output) MustValidOutput()

MustValidOutput checks if amount and lock constraints are as expected

func (*Output) NumConstraints

func (o *Output) NumConstraints() int

func (*Output) PushConstraint

func (o *Output) PushConstraint(c []byte) (byte, error)

PushConstraint can only be used inside r/o override closure

func (*Output) PutAmount

func (o *Output) PutAmount(amount uint64)

func (*Output) PutConstraint

func (o *Output) PutConstraint(c []byte, idx byte)

PutConstraint can only be used inside r/o override closure

func (*Output) PutLock

func (o *Output) PutLock(lock Lock)

func (*Output) SenderED25519

func (o *Output) SenderED25519() (AddressED25519, byte)

SenderED25519 return sender address and constraintIndex if found, otherwise nil, 0xff

func (*Output) SequencerOutputData

func (o *Output) SequencerOutputData() (*SequencerOutputData, bool)

func (*Output) StemLock

func (o *Output) StemLock() (*StemLock, bool)

func (*Output) TimeLock

func (o *Output) TimeLock() (uint32, bool)

func (*Output) ToString

func (o *Output) ToString(prefix ...string) string

func (*Output) WithAmount

func (o *Output) WithAmount(amount uint64) *Output

WithAmount can only be used inside r/o override closure

func (*Output) WithLock

func (o *Output) WithLock(lock Lock) *Output

WithLock can only be used inside r/o override closure

type OutputDataWithChainID

type OutputDataWithChainID struct {
	OutputDataWithID
	ChainID ChainID
}

type OutputDataWithID

type OutputDataWithID struct {
	ID         OutputID
	OutputData []byte
}

func (*OutputDataWithID) MustParse

func (o *OutputDataWithID) MustParse() *OutputWithID

func (*OutputDataWithID) Parse

func (o *OutputDataWithID) Parse(validOpt ...func(o *Output) error) (*OutputWithID, error)

func (*OutputDataWithID) ParseAsChainOutput

func (o *OutputDataWithID) ParseAsChainOutput() (*OutputWithChainID, byte, error)

type OutputID

type OutputID [OutputIDLength]byte

func GenesisOutputID

func GenesisOutputID() (ret OutputID)

func GenesisStemOutputID

func GenesisStemOutputID() (ret OutputID)

func NewOutputID

func NewOutputID(id *TransactionID, idx byte) (ret OutputID)

func OutputIDFromBytes

func OutputIDFromBytes(data []byte) (ret OutputID, err error)

func OutputIDFromHexString

func OutputIDFromHexString(str string) (ret OutputID, err error)

func (*OutputID) Bytes

func (oid *OutputID) Bytes() []byte

func (*OutputID) Index

func (oid *OutputID) Index() byte

func (*OutputID) IsBranchTransaction

func (oid *OutputID) IsBranchTransaction() bool

func (*OutputID) IsSequencerTransaction

func (oid *OutputID) IsSequencerTransaction() bool

func (*OutputID) Slot

func (oid *OutputID) Slot() Slot

func (*OutputID) String

func (oid *OutputID) String() string

func (*OutputID) StringHex

func (oid *OutputID) StringHex() string

func (*OutputID) StringShort

func (oid *OutputID) StringShort() string

func (*OutputID) StringVeryShort

func (oid *OutputID) StringVeryShort() string

func (*OutputID) Timestamp

func (oid *OutputID) Timestamp() Time

func (*OutputID) TransactionHash

func (oid *OutputID) TransactionHash() (ret TransactionIDShort)

func (*OutputID) TransactionID

func (oid *OutputID) TransactionID() (ret TransactionID)

type OutputWithChainID

type OutputWithChainID struct {
	OutputWithID
	ChainID                    ChainID
	PredecessorConstraintIndex byte
}

func GenesisOutput

func GenesisOutput(initialSupply uint64, controllerAddress AddressED25519) *OutputWithChainID

type OutputWithID

type OutputWithID struct {
	ID     OutputID
	Output *Output
}

func GenesisStemOutput

func GenesisStemOutput() *OutputWithID

func (*OutputWithID) AsChainOutput

func (o *OutputWithID) AsChainOutput() (*OutputWithChainID, error)

func (*OutputWithID) Clone

func (o *OutputWithID) Clone() *OutputWithID

func (*OutputWithID) ExtractChainID

func (o *OutputWithID) ExtractChainID() (ChainID, byte, bool)

ExtractChainID return chainID, predecessor constraint index, existence flag

func (*OutputWithID) IDShort

func (o *OutputWithID) IDShort() string

func (*OutputWithID) MustAsChainOutput

func (o *OutputWithID) MustAsChainOutput() *OutputWithChainID

func (*OutputWithID) Short

func (o *OutputWithID) Short() string

func (*OutputWithID) String

func (o *OutputWithID) String() string

func (*OutputWithID) Timestamp

func (o *OutputWithID) Timestamp() Time

type Parser

type Parser func([]byte) (Constraint, error)

type RoyaltiesED25519

type RoyaltiesED25519 struct {
	Address AddressED25519
	Amount  uint64
}

func NewRoyalties

func NewRoyalties(addr AddressED25519, amount uint64) *RoyaltiesED25519

func RoyaltiesED25519FromBytes

func RoyaltiesED25519FromBytes(data []byte) (*RoyaltiesED25519, error)

func (*RoyaltiesED25519) Bytes

func (cl *RoyaltiesED25519) Bytes() []byte

func (*RoyaltiesED25519) Name

func (cl *RoyaltiesED25519) Name() string

func (RoyaltiesED25519) String

func (cl RoyaltiesED25519) String() string

type SenderED25519

type SenderED25519 struct {
	Address AddressED25519
}

func NewSenderED25519

func NewSenderED25519(addr AddressED25519) *SenderED25519

func SenderED25519FromBytes

func SenderED25519FromBytes(data []byte) (*SenderED25519, error)

func (*SenderED25519) Bytes

func (s *SenderED25519) Bytes() []byte

func (*SenderED25519) Name

func (s *SenderED25519) Name() string

func (*SenderED25519) String

func (s *SenderED25519) String() string

type SequencerConstraint

type SequencerConstraint struct {
	// must point to the sibling chain constraint
	ChainConstraintIndex byte
	// must be equal to the total produced amount of the transaction
	TotalProducedAmount uint64
}

func NewSequencerConstraint

func NewSequencerConstraint(chainConstraintIndex byte, totalProducedAmount uint64) *SequencerConstraint

func SequencerConstraintFromBytes

func SequencerConstraintFromBytes(data []byte) (*SequencerConstraint, error)

func (*SequencerConstraint) Bytes

func (s *SequencerConstraint) Bytes() []byte

func (*SequencerConstraint) Name

func (s *SequencerConstraint) Name() string

func (*SequencerConstraint) String

func (s *SequencerConstraint) String() string

type SequencerOutputData

type SequencerOutputData struct {
	SequencerConstraint      *SequencerConstraint
	ChainConstraint          *ChainConstraint
	AmountOnChain            uint64
	SequencerConstraintIndex byte
}

type Slot

type Slot uint32

Slot represents a particular time slot. Starting slot 0 at genesis

func SlotFromBytes

func SlotFromBytes(data []byte) (ret Slot, err error)

SlotFromBytes enforces 2 most significant bits of the first byte are 0

func (Slot) Bytes

func (e Slot) Bytes() []byte

func (Slot) Hex

func (e Slot) Hex() string

type StateIndex

type StateIndex struct {
	ChainBlockIndex byte
	StateIndex      uint32
}

func NewStateIndex

func NewStateIndex(chainBlockIndex byte, stateIndex uint32) *StateIndex

func StateIndexFromBytes

func StateIndexFromBytes(data []byte) (*StateIndex, error)

func (*StateIndex) Bytes

func (s *StateIndex) Bytes() []byte

func (*StateIndex) Name

func (_ *StateIndex) Name() string

func (*StateIndex) String

func (s *StateIndex) String() string

type StemLock

type StemLock struct {
	PredecessorOutputID OutputID
}

func StemLockFromBytes

func StemLockFromBytes(data []byte) (*StemLock, error)

func (*StemLock) AccountID

func (st *StemLock) AccountID() AccountID

func (*StemLock) Accounts

func (st *StemLock) Accounts() []Accountable

func (*StemLock) AsLock

func (st *StemLock) AsLock() Lock

func (*StemLock) Bytes

func (st *StemLock) Bytes() []byte

func (*StemLock) Name

func (st *StemLock) Name() string

func (*StemLock) String

func (st *StemLock) String() string

type Tick

type Tick byte

Tick is enforced to be <= MaxTickValueInSlot of the ledger identity Usually it is 100, can be up to 255

func TickFromByte

func TickFromByte(d byte) (ret Tick, err error)

func (Tick) String

func (s Tick) String() string

func (Tick) Valid

func (s Tick) Valid() bool

type Time

type Time [TimeByteLength]byte

Time (ledger time) is 5 bytes: - bytes [0:3] is slot (big endian). Most significant of the byte 0 in the slot must be 0 - byte 4 is tick

var (
	NilLedgerTime Time
)

func MaxTime

func MaxTime(ts ...Time) Time

func MustNewLedgerTime

func MustNewLedgerTime(e Slot, s Tick) (ret Time)

func TimeFromBytes

func TimeFromBytes(data []byte) (ret Time, err error)

func TimeFromRealTime

func TimeFromRealTime(nowis time.Time) Time

func TimeNow

func TimeNow() Time

func (Time) AddDuration

func (t Time) AddDuration(d time.Duration) Time

func (Time) AddSlots

func (t Time) AddSlots(e int) Time

func (Time) AddTicks

func (t Time) AddTicks(s int) Time

func (Time) After

func (t Time) After(t1 Time) bool

func (Time) AsFileName

func (t Time) AsFileName() string

func (Time) Before

func (t Time) Before(t1 Time) bool

func (Time) Bytes

func (t Time) Bytes() []byte

func (Time) Hex

func (t Time) Hex() string

func (Time) IsSlotBoundary

func (t Time) IsSlotBoundary() bool

func (Time) NextSlotBoundary

func (t Time) NextSlotBoundary() Time

func (Time) Short

func (t Time) Short() string

func (Time) Slot

func (t Time) Slot() Slot

func (Time) Source

func (t Time) Source() string

func (Time) String

func (t Time) String() string

func (Time) SubtractSlotsSafe

func (t Time) SubtractSlotsSafe(s Slot) Time

func (Time) Tick

func (t Time) Tick() Tick

func (Time) TicksToNextSlotBoundary

func (t Time) TicksToNextSlotBoundary() int

func (Time) Time

func (t Time) Time() time.Time

func (Time) UnixNano

func (t Time) UnixNano() int64

type Timelock

type Timelock Slot

func NewTimelock

func NewTimelock(timeSlot Slot) Timelock

func TimelockFromBytes

func TimelockFromBytes(data []byte) (Timelock, error)

func (Timelock) Bytes

func (t Timelock) Bytes() []byte

func (Timelock) Name

func (t Timelock) Name() string

func (Timelock) String

func (t Timelock) String() string

type TotalAmount

type TotalAmount uint64

func NewTotalAmount

func NewTotalAmount(a uint64) TotalAmount

func TotalAmountFromBytes

func TotalAmountFromBytes(data []byte) (TotalAmount, error)

func (TotalAmount) Amount

func (a TotalAmount) Amount() uint64

func (TotalAmount) Bytes

func (a TotalAmount) Bytes() []byte

func (TotalAmount) Name

func (a TotalAmount) Name() string

func (TotalAmount) String

func (a TotalAmount) String() string

type TransactionID

type TransactionID [TransactionIDLength]byte

TransactionID : [0:5] - timestamp bytes [5:32] TransactionIDShort

func GenesisTransactionID

func GenesisTransactionID() *TransactionID

func NewTransactionID

func NewTransactionID(ts Time, h TransactionIDShort, sequencerTxFlag bool) (ret TransactionID)

func RandomTransactionID

func RandomTransactionID(sequencerFlag bool) TransactionID

RandomTransactionID not completely random. For testing

func TransactionIDFromBytes

func TransactionIDFromBytes(data []byte) (ret TransactionID, err error)

func TransactionIDFromHexString

func TransactionIDFromHexString(str string) (ret TransactionID, err error)

func (*TransactionID) AsFileName

func (txid *TransactionID) AsFileName() string

func (*TransactionID) Bytes

func (txid *TransactionID) Bytes() []byte

func (*TransactionID) IsBranchTransaction

func (txid *TransactionID) IsBranchTransaction() bool

func (*TransactionID) IsSequencerMilestone

func (txid *TransactionID) IsSequencerMilestone() bool

func (*TransactionID) MarshalJSON

func (txid *TransactionID) MarshalJSON() ([]byte, error)

func (*TransactionID) ShortID

func (txid *TransactionID) ShortID() (ret TransactionIDShort)

ShortID return hash part of ID

func (*TransactionID) Slot

func (txid *TransactionID) Slot() Slot

func (*TransactionID) String

func (txid *TransactionID) String() string

func (*TransactionID) StringHex

func (txid *TransactionID) StringHex() string

func (*TransactionID) StringShort

func (txid *TransactionID) StringShort() string

func (*TransactionID) StringVeryShort

func (txid *TransactionID) StringVeryShort() string

func (*TransactionID) Timestamp

func (txid *TransactionID) Timestamp() (ret Time)

func (*TransactionID) UnmarshalJSON

func (txid *TransactionID) UnmarshalJSON(hexStrData []byte) error

func (*TransactionID) VeryShortID4

func (txid *TransactionID) VeryShortID4() (ret TransactionIDVeryShort4)

VeryShortID4 returns first 8 bytes of the ShortID, i.e. of the hash Collisions cannot be ruled out! Intended use is in Bloom filtering, when false positives are acceptable

func (*TransactionID) VeryShortID8

func (txid *TransactionID) VeryShortID8() (ret TransactionIDVeryShort8)

VeryShortID8 returns first 8 bytes of the ShortID, i.e. of the hash Collisions cannot be ruled out! Intended use is in Bloom filtering, when false positives are acceptable

type TransactionIDShort

type TransactionIDShort [TransactionIDShortLength]byte

TransactionIDShort is [0:28] of the blake2b 32-byte hash of transaction bytes

func HashTransactionBytes

func HashTransactionBytes(txBytes []byte) (ret TransactionIDShort)

type TransactionIDVeryShort4

type TransactionIDVeryShort4 [4]byte

TransactionIDVeryShort4 is first 4 bytes of TransactionIDShort. Warning. Collisions cannot be ruled out

type TransactionIDVeryShort8

type TransactionIDVeryShort8 [8]byte

TransactionIDVeryShort8 is first 8 bytes of TransactionIDShort. Warning. Collisions cannot be ruled out

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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