ledger

package
v0.0.0-...-4d02eb9 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 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 is a constant
	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           = 40 * time.Millisecond
	DefaultSlotDuration           = DefaultTickDuration * TicksPerSlot // ~10.24 sec
	DaysPerYear                   = 365
	DefaultInflationEpochDuration = DaysPerYear * 24 * time.Hour // standard inflation epoch is 365 days
	DefaultSlotsPerInflationEpoch = uint64(DefaultInflationEpochDuration / DefaultSlotDuration)

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

	DefaultBranchInflationBonusBase       = 5_000_000
	DefaultChainInflationPerTickBase      = 160_000
	DefaultChainInflationOpportunitySlots = 12
	DefaultTicksPerInflationEpoch         = DefaultSlotsPerInflationEpoch * TicksPerSlot

	TargetAnnualChainInflationRateUpper = 13
	TargetAnnualChainInflationRateLower = 12

	DefaultVBCost                   = 1
	DefaultTransactionPace          = 25
	DefaultTransactionPaceSequencer = 3
	// DefaultMinimumAmountOnSequencer Reasonable limit could be 1/1000 of initial supply
	DefaultMinimumAmountOnSequencer    = 1_000 * PRXI
	DefaultMaxNumberOfEndorsements     = 8
	DefaultPreBranchConsolidationTicks = 50
)
View Source
const (
	SlotByteLength = 4
	TimeByteLength = SlotByteLength + 1 // bytes
	MaxSlot        = 0xffffffff >> 1    // 1 most significant bit must be 0
	MaxTick        = 0xff
	MaxTime        = (MaxSlot << 8) | MaxTick
	TicksPerSlot   = MaxTick + 1
)
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"
	AddressED25519Name = "a"
)
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 (
	StemLockName = "stemLock"
)
View Source
const (
	TimelockName = "timelock"
)
View Source
const (
	TotalAmountConstraintName = "total"
)

Variables

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 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 EqualOutputs

func EqualOutputs(o1, o2 *OutputWithID) 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 SlotDuration

func SlotDuration() time.Duration

func TickDuration

func TickDuration() time.Duration

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

ValidSequencerPace return true is subsequent input and target sequencer tx timestamps make a valid pace

func ValidSlot

func ValidSlot(slot Slot) bool

func ValidTime

func ValidTime(ts Time) bool

func ValidTransactionPace

func ValidTransactionPace(t1, t2 Time) bool

ValidTransactionPace return true is subsequent input and target non-sequencer tx timestamps make a valid pace

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

BoostrapSequencerID is a constant

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
	// ----------- begin inflation-related
	// BranchInflationBonusBase inflation bonus
	BranchInflationBonusBase uint64
	// ChainInflationPerTickBase is maximum total inflation per one tick. It is fixed amount for the ledger
	// It is equal to the inflation which generates the whole supply per one tick
	ChainInflationPerTickBase uint64
	// TicksPerInflationEpoch usually equal to 1 standard year with 365 days
	TicksPerInflationEpoch uint64
	// ChainInflationOpportunitySlots maximum gap between chain outputs for the non-zero inflation
	ChainInflationOpportunitySlots uint64
	// ----------- end inflation-related
	// 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
	// PreBranchConsolidationTicks enforces endorsement-only constraint for specified amount of ticks
	// before the slot boundary. It means, sequencer transaction can have only one input, its own predecessor
	// for any transaction with timestamp ticks > MaxTickValueInSlot - PreBranchConsolidationTicks
	// value 0 of PreBranchConsolidationTicks effectively means no constraint
	PreBranchConsolidationTicks uint8
}

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 IdentityDataFromBytes

func IdentityDataFromBytes(data []byte) (*IdentityData, error)

func MustIdentityDataFromBytes

func MustIdentityDataFromBytes(data []byte) *IdentityData

func StateIdentityDataFromYAML

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

func (*IdentityData) Bytes

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

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) IsPreBranchConsolidationTimestamp

func (id *IdentityData) IsPreBranchConsolidationTimestamp(ts Time) bool

func (*IdentityData) LedgerTimeFromClockTime

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

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) SlotsPerYear

func (id *IdentityData) SlotsPerYear() int

func (*IdentityData) String

func (id *IdentityData) String() string

func (*IdentityData) TicksPerYear

func (id *IdentityData) TicksPerYear() int

func (*IdentityData) TimeConstantsToString

func (id *IdentityData) TimeConstantsToString() string

func (*IdentityData) TimeToTicksSinceGenesis

func (id *IdentityData) TimeToTicksSinceGenesis(nowis time.Time) int64

TimeToTicksSinceGenesis converts time value into ticks since genesis

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"`
	VBCost                         uint64 `yaml:"vb_cost"`
	TransactionPace                byte   `yaml:"transaction_pace"`
	TransactionPaceSequencer       byte   `yaml:"transaction_pace_sequencer"`
	BranchInflationBonusBase       uint64 `yaml:"branch_inflation_bonus_base"`
	ChainInflationPerTickBase      uint64 `yaml:"chain_inflation_per_tick_base"`
	ChainInflationOpportunitySlots uint64 `yaml:"chain_inflation_opportunity_slots"`
	TicksPerInflationEpoch         uint64 `yaml:"ticks_per_inflation_epoch"`
	MinimumAmountOnSequencer       uint64 `yaml:"minimum_amount_on_sequencer"`
	MaxNumberOfEndorsements        uint64 `yaml:"max_number_of_endorsements"`
	PreBranchConsolidationTicks    uint8  `yaml:"pre_branch_consolidation_ticks"`
	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 {
	// ChainInflation inflation amount calculated according to chain inflation rule. It is used inside slot and delayed on slot boundary
	// and can be added to the inflation of the next transaction in the chain
	ChainInflation uint64
	// VRFProof VRF randomness proof, used to proof VRF and calculate inflation amount on branch
	// nil for non-branch transactions
	VRFProof []byte
	// ChainConstraintIndex must point to the sibling chain constraint
	ChainConstraintIndex byte
	// DelayedInflationIndex
	// Used only if branch successor to enforce correct ChainInflation which will sum of delayed inflation and current inflation
	// If not used, must be 0xff
	DelayedInflationIndex byte
}

func InflationConstraintFromBytes

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

func (*InflationConstraint) Bytes

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

func (*InflationConstraint) InflationAmount

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

InflationAmount calculates inflation amount either inside slot, or on the slot boundary

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) AmountFactor

func (lib *Library) AmountFactor(inTs Time, inAmount uint64) uint64

func (*Library) BranchInflationBonusFromRandomnessProof

func (lib *Library) BranchInflationBonusFromRandomnessProof(proof []byte) uint64

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

func (*Library) CalcChainInflationAmount

func (lib *Library) CalcChainInflationAmount(inTs, outTs Time, inAmount, delayed uint64) uint64

CalcChainInflationAmount interprets EasyFl formula. Return chain inflation amount for given in and out ledger times, input amount of tokens and delayed

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) InsideInflationOpportunityWindow

func (lib *Library) InsideInflationOpportunityWindow(diffTicks int64) bool

InsideInflationOpportunityWindow returns if ticks and amount are inside inflation opportunity window Outside inflation opportunity window mean 0 inflation

func (*Library) UpperSupplyBound

func (lib *Library) UpperSupplyBound(inTs Time) uint64

type LibraryConst

type LibraryConst struct {
	*Library
}

func (LibraryConst) MinimumAmountOnSequencer

func (lib LibraryConst) MinimumAmountOnSequencer() uint64

func (LibraryConst) TicksPerInflationEpoch

func (lib LibraryConst) TicksPerInflationEpoch() uint64

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 of the output
	Lock Lock
	// Balance amount of tokens on the output
	Balance uint64
	// ChainOrigin true if start a chain on this output by adding chain constrain (origin)
	//	 false for simple ED25519 account balance (no chain origin added)
	ChainOrigin bool
}

LockBalance is an amount/target pair used in distribution list One LockBalance results in one produced output on the transaction

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)

ParseAsChainOutput parses raw output data expecting chain output. Returns parsed output and index of the chain constraint in it

type OutputID

type OutputID [OutputIDLength]byte

func GenesisOutputID

func GenesisOutputID() (ret OutputID)

GenesisOutputID independent on ledger constants, except GenesisOutputIndex which is byte(0)

func GenesisStemOutputID

func GenesisStemOutputID() (ret OutputID)

GenesisStemOutputID independent on ledger constants, except GenesisStemOutputIndex which is byte(1)

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) Lines

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

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
	MilestoneData            *MilestoneData
}

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 (s Slot) Bytes() []byte

func (Slot) Hex

func (s Slot) Hex() string

func (Slot) TransactionIDPrefixes

func (s Slot) TransactionIDPrefixes() (withSequencerFlag, withoutSequencerFlag []byte)

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 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 MaximumTime

func MaximumTime(ts ...Time) Time

func NewLedgerTime

func NewLedgerTime(slot Slot, t uint8) (ret Time)

func TimeFromBytes

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

func TimeFromClockTime

func TimeFromClockTime(nowis time.Time) Time

func TimeFromTicksSinceGenesis

func TimeFromTicksSinceGenesis(ticks int64) (ret Time, err error)

TimeFromTicksSinceGenesis converts absolute value of ticks since genesis into the time value

func TimeNow

func TimeNow() Time

func (Time) AddSlots

func (t Time) AddSlots(slot Slot) Time

AddSlots adds slots to timestamp

func (Time) AddTicks

func (t Time) AddTicks(ticks int) Time

AddTicks adds ticks to timestamp. Ticks can be negative

func (Time) After

func (t Time) After(t1 Time) bool

func (Time) AfterOrEqual

func (t Time) AfterOrEqual(t1 Time) bool

func (Time) AsFileName

func (t Time) AsFileName() string

func (Time) Before

func (t Time) Before(t1 Time) bool

func (Time) BeforeOrEqual

func (t Time) BeforeOrEqual(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) Tick

func (t Time) Tick() uint8

func (Time) TicksSinceGenesis

func (t Time) TicksSinceGenesis() int64

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

GenesisTransactionID independent on any ledger constants

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