types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PartitionIdentifierLength = 4
	NetworkIdentifierLength   = 2
)
View Source
const (
	UnicitySealTag
	RootGenesisTag
	GenesisRootRecordTag
	ConsensusParamsTag
	GenesisPartitionRecordTag
	PartitionNodeTag
	UnicityCertificateTag
	InputRecordTag
	TxProofTag
	UnitStateProofTag
	PartitionDescriptionRecordTag
	BlockTag
	RootTrustBaseTag
	UnicityTreeCertificateTag
	TransactionRecordTag
	TransactionOrderTag
	RootPartitionBlockDataTag
	RootPartitionRoundInfoTag
)
View Source
const GenesisTime uint64 = 1681971084

GenesisTime min timestamp Thursday, April 20, 2023 6:11:24 AM GMT+00:00 Epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT)

Variables

View Source
var (
	ErrInputRecordIsNil      = errors.New("input record is nil")
	ErrHashIsNil             = errors.New("hash is nil")
	ErrBlockHashIsNil        = errors.New("block hash is nil")
	ErrPreviousHashIsNil     = errors.New("previous hash is nil")
	ErrSummaryValueIsNil     = errors.New("summary value is nil")
	ErrInvalidPartitionRound = errors.New("partition round is 0")
)
View Source
var (
	ErrTransactionRecordIsNil = errors.New("transaction record is nil")
	ErrTransactionOrderIsNil  = errors.New("transaction order is nil")
	ErrServerMetadataIsNil    = errors.New("server metadata is nil")
)
View Source
var (
	ErrTxRecordProofIsNil = errors.New("transaction record proof is nil")
	ErrOutOfGas           = errors.New("out of gas")
)
View Source
var (
	ErrUnicitySealIsNil          = errors.New("unicity seal is nil")
	ErrSignerIsNil               = errors.New("signer is nil")
	ErrUnicitySealHashIsNil      = errors.New("hash is nil")
	ErrInvalidRootRound          = errors.New("invalid root round number")
	ErrUnicitySealSignatureIsNil = errors.New("no signatures")
	ErrRootValidatorInfoMissing  = errors.New("root node info is missing")
	ErrInvalidTimestamp          = errors.New("invalid timestamp")
)
View Source
var (
	ErrUnicityTreeCertificateIsNil = errors.New("unicity tree certificate is nil")
	ErrUCIsNil                     = errors.New("new UC is nil")
	ErrLastUCIsNil                 = errors.New("last UC is nil")
)
View Source
var (
	Cbor = cborHandler{}
)
View Source
var (
	ErrBlockIsNil = errors.New("block is nil")
)
View Source
var (
	ErrSystemDescriptionIsNil = errors.New("system description record is nil")
)
View Source
var ErrUnicityCertificateIsNil = errors.New("unicity certificate is nil")

Functions

func AssertEqualIR

func AssertEqualIR(a, b *InputRecord) error

func BlockHash

func BlockHash(algorithm crypto.Hash, h *Header, txs []*TransactionRecord, stateHash []byte, prevStateHash []byte) ([]byte, error)

BlockHash returns the hash of the block. Hash of a block is computed as hash of block header fields and tree hash of transactions.

func CheckNonEquivocatingCertificates

func CheckNonEquivocatingCertificates(prevUC, newUC *UnicityCertificate) error

CheckNonEquivocatingCertificates checks if provided certificates are equivocating NB! order is important, also it is assumed that validity of both UCs is checked before The algorithm is based on Yellowpaper: "Algorithm 6 Checking two UC-s for equivocation"

func EnsureVersion

func EnsureVersion(data Versioned, actual, expected ABVersion) error

func EqualIR

func EqualIR(a, b *InputRecord) (bool, error)

func ErrInvalidVersion

func ErrInvalidVersion(s Versioned) error

func HashCBOR

func HashCBOR(data any, hashAlgorithm crypto.Hash) ([]byte, error)

HashCBOR encodes the provided "data" to CBOR and calculates hash using the provided "hashAlgorithm". The "data" parameter should be a CBOR struct with the "toarray" tag. The purpose of CBOR encoding before hashing is to avoid "field offset attacks" e.g. when two structs of the same type, but with different values, would yield the same hash if otherwise normally concatenated.

func NewTimestamp

func NewTimestamp() uint64

NewTimestamp - returns timestamp in seconds from epoch

func VerifyTxProof

func VerifyTxProof(txRecordProof *TxRecordProof, tb RootTrustBase, hashAlgorithm crypto.Hash) error

func VerifyUnitStateProof

func VerifyUnitStateProof(u *UnitStateProof, algorithm crypto.Hash, unitData *StateUnitData, ucv UnicityCertificateValidator) error

Types

type ABTag

type ABTag = uint64

type ABVersion

type ABVersion = uint32

type AuthProofSigData

type AuthProofSigData struct {
	Version ABVersion
	Payload
	StateUnlock []byte
	// contains filtered or unexported fields
}

type Block

type Block struct {
	Header             *Header
	Transactions       []*TransactionRecord
	UnicityCertificate TaggedCBOR
	// contains filtered or unexported fields
}

func (*Block) CalculateBlockHash

func (b *Block) CalculateBlockHash(algorithm crypto.Hash) (*InputRecord, error)

CalculateBlockHash calculates the block hash, updates UC and returns the updated input record with the block hash.

func (*Block) GetBlockFees

func (b *Block) GetBlockFees() (uint64, error)

func (*Block) GetProposerID

func (b *Block) GetProposerID() string

func (*Block) GetRoundNumber

func (b *Block) GetRoundNumber() (uint64, error)

func (*Block) HeaderHash

func (b *Block) HeaderHash(algorithm crypto.Hash) ([]byte, error)

func (*Block) InputRecord

func (b *Block) InputRecord() (*InputRecord, error)

func (*Block) IsValid

func (b *Block) IsValid(algorithm crypto.Hash, systemDescriptionHash []byte) error

func (*Block) PartitionID

func (b *Block) PartitionID() PartitionID

func (*Block) Size

func (b *Block) Size() (bs uint64, _ error)

Size returns Block Size value used in Certification Request.

type ClientMetadata

type ClientMetadata struct {
	Timeout           uint64
	MaxTransactionFee uint64
	FeeCreditRecordID []byte
	ReferenceNumber   []byte
	// contains filtered or unexported fields
}

func (*ClientMetadata) GetFeeCreditRecordID

func (c *ClientMetadata) GetFeeCreditRecordID() []byte

func (*ClientMetadata) GetMaxFee

func (c *ClientMetadata) GetMaxFee() uint64

func (*ClientMetadata) GetReferenceNumber

func (c *ClientMetadata) GetReferenceNumber() []byte

func (*ClientMetadata) GetTimeout

func (c *ClientMetadata) GetTimeout() uint64

type FeeCreditBill

type FeeCreditBill struct {
	UnitID         UnitID         `json:"unitId"`
	OwnerPredicate PredicateBytes `json:"ownerPredicate"`
	// contains filtered or unexported fields
}

type FeeProofSigData

type FeeProofSigData struct {
	Version ABVersion
	Payload
	StateUnlock []byte
	AuthProof   RawCBOR
	// contains filtered or unexported fields
}

type GenericChainItem

type GenericChainItem struct {
	Hash []byte
	Left bool
	// contains filtered or unexported fields
}
type Header struct {
	Version           ABVersion
	PartitionID       PartitionID
	ShardID           ShardID
	ProposerID        string
	PreviousBlockHash hex.Bytes
	// contains filtered or unexported fields
}

func (*Header) GetVersion

func (h *Header) GetVersion() ABVersion

func (*Header) Hash

func (h *Header) Hash(algorithm crypto.Hash) ([]byte, error)

func (*Header) IsValid

func (h *Header) IsValid() error

func (*Header) MarshalCBOR

func (h *Header) MarshalCBOR() ([]byte, error)

func (*Header) UnmarshalCBOR

func (h *Header) UnmarshalCBOR(data []byte) error

type InputRecord

type InputRecord struct {
	Version         ABVersion `json:"version"`
	PreviousHash    hex.Bytes `json:"previousHash"`    // previously certified state hash
	Hash            hex.Bytes `json:"hash"`            // state hash to be certified
	BlockHash       hex.Bytes `json:"blockHash"`       // hash of the block
	SummaryValue    hex.Bytes `json:"summaryValue"`    // summary value to certified
	Timestamp       uint64    `json:"timestamp"`       // reference time for transaction validation
	RoundNumber     uint64    `json:"roundNumber"`     // shard's round number
	Epoch           uint64    `json:"epoch"`           // shard’s epoch number
	SumOfEarnedFees uint64    `json:"sumOfEarnedFees"` // sum of the actual fees over all transaction records in the block
	// contains filtered or unexported fields
}

Shard input record (IR) of a shard of a partition.

func (*InputRecord) AddToHasher

func (x *InputRecord) AddToHasher(hasher abhash.Hasher)

func (*InputRecord) Bytes

func (x *InputRecord) Bytes() ([]byte, error)

func (*InputRecord) GetVersion

func (x *InputRecord) GetVersion() ABVersion

func (*InputRecord) IsValid

func (x *InputRecord) IsValid() error

func (*InputRecord) MarshalCBOR

func (x *InputRecord) MarshalCBOR() ([]byte, error)

func (*InputRecord) NewRepeatIR

func (x *InputRecord) NewRepeatIR() *InputRecord

NewRepeatIR - creates new repeat IR from current IR

func (*InputRecord) String

func (x *InputRecord) String() string

func (*InputRecord) UnmarshalCBOR

func (x *InputRecord) UnmarshalCBOR(data []byte) error

type NetworkID

type NetworkID uint16
const (
	NetworkMainNet NetworkID = 1
	NetworkTestNet NetworkID = 2
	NetworkLocal   NetworkID = 3
)

func (NetworkID) Bytes

func (nid NetworkID) Bytes() []byte

type NodeInfo

type NodeInfo struct {
	NodeID    string    `json:"nodeId"`    // node identifier derived from node's encryption public key
	PublicKey hex.Bytes `json:"publicKey"` // the trust base signing public key
	Stake     uint64    `json:"stake"`     // amount of staked alpha for this node, currently unused as each nodes get equal votes regardless of stake
	// contains filtered or unexported fields
}

func NewNodeInfo

func NewNodeInfo(nodeID string, stake uint64, verifier abcrypto.Verifier) *NodeInfo

NewNodeInfo creates new NodeInfo, caching the verifier in private field.

func (*NodeInfo) Bytes

func (n *NodeInfo) Bytes() []byte

Bytes serializes all fields.

type Option

type Option func(c *trustBaseConf)

func WithQuorumThreshold

func WithQuorumThreshold(threshold uint64) Option

WithQuorumThreshold overrides the default 2/3+1 quorum threshold.

type PartitionDescriptionRecord

type PartitionDescriptionRecord struct {
	Version             ABVersion   `json:"version"`
	NetworkIdentifier   NetworkID   `json:"networkIdentifier"`
	PartitionIdentifier PartitionID `json:"partitionIdentifier"`
	// System Type Descriptor is only used (ie is not nil) when PartitionIdentifier == 0
	SystemDescriptor *SystemTypeDescriptor `json:"systemTypeDescriptor,omitempty"`
	TypeIdLen        uint32                `json:"typeIdLength"`
	UnitIdLen        uint32                `json:"unitIdLength"`
	Shards           ShardingScheme        `json:"shardingScheme"`
	SummaryTrustBase hex.Bytes             `json:"summaryTrustBase"`
	T2Timeout        time.Duration         `json:"t2timeout"`
	FeeCreditBill    *FeeCreditBill        `json:"feeCreditBill"`
	// contains filtered or unexported fields
}

func (*PartitionDescriptionRecord) GetNetworkIdentifier

func (pdr *PartitionDescriptionRecord) GetNetworkIdentifier() NetworkID

func (*PartitionDescriptionRecord) GetPartitionIdentifier

func (pdr *PartitionDescriptionRecord) GetPartitionIdentifier() PartitionID

func (*PartitionDescriptionRecord) GetVersion

func (pdr *PartitionDescriptionRecord) GetVersion() ABVersion

func (*PartitionDescriptionRecord) Hash

func (pdr *PartitionDescriptionRecord) Hash(hashAlgorithm crypto.Hash) ([]byte, error)

func (*PartitionDescriptionRecord) IsValid

func (pdr *PartitionDescriptionRecord) IsValid() error

func (*PartitionDescriptionRecord) IsValidShard

func (pdr *PartitionDescriptionRecord) IsValidShard(id ShardID) error

IsValidShard checks if the argument is a valid shard ID in the Partition.

func (*PartitionDescriptionRecord) MarshalCBOR

func (pdr *PartitionDescriptionRecord) MarshalCBOR() ([]byte, error)

func (*PartitionDescriptionRecord) UnitIdValidator

func (pdr *PartitionDescriptionRecord) UnitIdValidator(sid ShardID) func(unitID UnitID) error

UnitIdValidator returns function which checks that unit ID passed as argument has correct length and that the unit belongs into the given shard.

func (*PartitionDescriptionRecord) UnmarshalCBOR

func (pdr *PartitionDescriptionRecord) UnmarshalCBOR(data []byte) error

type PartitionID

type PartitionID uint32

func BytesToPartitionID

func BytesToPartitionID(b []byte) (PartitionID, error)

func (PartitionID) Bytes

func (sid PartitionID) Bytes() []byte

func (PartitionID) String

func (sid PartitionID) String() string

type Payload

type Payload struct {
	NetworkID      NetworkID
	PartitionID    PartitionID
	UnitID         UnitID
	Type           uint16
	Attributes     RawCBOR // transaction type specific attributes
	StateLock      *StateLock
	ClientMetadata *ClientMetadata // metadata about the transaction added by the client
	// contains filtered or unexported fields
}

Payload helper struct for transaction signing. Includes all TransactionOrder fields except for the signatures themselves (StateUnlock, AuthProof and FeeProof). Payload is an embedded field of TransactionOrder so that the fields get "flattened" in CBOR encoding.

type PredicateBytes

type PredicateBytes = hex.Bytes

type RawCBOR

type RawCBOR []byte

func (RawCBOR) MarshalCBOR

func (r RawCBOR) MarshalCBOR() ([]byte, error)

MarshalCBOR returns r or CBOR nil if r is empty.

func (RawCBOR) MarshalText

func (r RawCBOR) MarshalText() ([]byte, error)

func (*RawCBOR) UnmarshalCBOR

func (r *RawCBOR) UnmarshalCBOR(data []byte) error

UnmarshalCBOR copies data into r unless it's CBOR "nil marker" - in that case r is set to empty slice.

func (*RawCBOR) UnmarshalText

func (r *RawCBOR) UnmarshalText(src []byte) error

type RootTrustBase

type RootTrustBase interface {
	VerifyQuorumSignatures(data []byte, signatures map[string]hex.Bytes) (error, []error)
	VerifySignature(data []byte, sig []byte, nodeID string) (uint64, error)
	GetQuorumThreshold() uint64
	GetMaxFaultyNodes() uint64
}

type RootTrustBaseV1

type RootTrustBaseV1 struct {
	Version           ABVersion            `json:"version"`
	Epoch             uint64               `json:"epoch"`             // current epoch number
	EpochStartRound   uint64               `json:"epochStartRound"`   // root chain round number when the epoch begins
	RootNodes         map[string]*NodeInfo `json:"rootNodes"`         // list of all root nodes for the current epoch
	QuorumThreshold   uint64               `json:"quorumThreshold"`   // amount of alpha required to reach consensus, currently each node gets equal amount of voting power i.e. +1 for each node
	StateHash         hex.Bytes            `json:"stateHash"`         // unicity tree root hash
	ChangeRecordHash  hex.Bytes            `json:"changeRecordHash"`  // epoch change request hash
	PreviousEntryHash hex.Bytes            `json:"previousEntryHash"` // previous trust base entry hash
	Signatures        map[string]hex.Bytes `json:"signatures"`        // signatures of previous epoch validators, over all fields except for the signatures fields itself
	// contains filtered or unexported fields
}

func NewTrustBaseFromFile

func NewTrustBaseFromFile(trustBaseFile string) (*RootTrustBaseV1, error)

NewTrustBaseFromFile loads trust base from file and caches verifiers.

func NewTrustBaseGenesis

func NewTrustBaseGenesis(nodes []*NodeInfo, unicityTreeRootHash []byte, opts ...Option) (*RootTrustBaseV1, error)

NewTrustBaseGenesis creates new unsigned root trust base with default genesis parameters.

func (*RootTrustBaseV1) GetMaxFaultyNodes

func (r *RootTrustBaseV1) GetMaxFaultyNodes() uint64

GetMaxFaultyNodes returns max allowed faulty nodes, only works if one node == one vote.

func (*RootTrustBaseV1) GetQuorumThreshold

func (r *RootTrustBaseV1) GetQuorumThreshold() uint64

GetQuorumThreshold returns the quorum threshold for the latest trust base entry.

func (*RootTrustBaseV1) GetVerifiers

func (r *RootTrustBaseV1) GetVerifiers() (map[string]abcrypto.Verifier, error)

GetVerifiers returns the cached verifiers.

func (*RootTrustBaseV1) GetVersion

func (r *RootTrustBaseV1) GetVersion() ABVersion

func (*RootTrustBaseV1) Hash

func (r *RootTrustBaseV1) Hash(hashAlgo crypto.Hash) ([]byte, error)

Hash hashes the entire structure including the signatures.

func (*RootTrustBaseV1) MarshalCBOR

func (r *RootTrustBaseV1) MarshalCBOR() ([]byte, error)

func (RootTrustBaseV1) SigBytes

func (r RootTrustBaseV1) SigBytes() ([]byte, error)

SigBytes serializes all fields expect for the signatures field.

func (*RootTrustBaseV1) Sign

func (r *RootTrustBaseV1) Sign(nodeID string, signer abcrypto.Signer) error

Sign signs the trust base entry, storing the signature to Signatures map.

func (*RootTrustBaseV1) UnmarshalCBOR

func (r *RootTrustBaseV1) UnmarshalCBOR(data []byte) error

func (*RootTrustBaseV1) VerifyQuorumSignatures

func (r *RootTrustBaseV1) VerifyQuorumSignatures(data []byte, signatures map[string]hex.Bytes) (error, []error)

VerifyQuorumSignatures verifies that the data is signed by enough root nodes so that quorum is reached, returns error if quorum is not reached, also returns list of any signature verification errors, regardless if quorum is reached or not.

func (*RootTrustBaseV1) VerifySignature

func (r *RootTrustBaseV1) VerifySignature(data []byte, sig []byte, nodeID string) (uint64, error)

VerifySignature verifies that the data is signed by the given root validator, returns the validator's stake if it is signed.

type ServerMetadata

type ServerMetadata struct {
	ActualFee         uint64
	TargetUnits       []UnitID
	SuccessIndicator  TxStatus
	ProcessingDetails RawCBOR
	// contains filtered or unexported fields
}

func (*ServerMetadata) ErrDetail

func (sm *ServerMetadata) ErrDetail() error

func (*ServerMetadata) GetActualFee

func (sm *ServerMetadata) GetActualFee() uint64

func (*ServerMetadata) GetTargetUnits

func (sm *ServerMetadata) GetTargetUnits() []UnitID

func (*ServerMetadata) SetError

func (sm *ServerMetadata) SetError(e error)

func (*ServerMetadata) TxStatus

func (sm *ServerMetadata) TxStatus() TxStatus

func (*ServerMetadata) UnmarshalDetails

func (sm *ServerMetadata) UnmarshalDetails(v any) error

type ShardID

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

func (ShardID) AddToHasher

func (id ShardID) AddToHasher(h abhash.Hasher)

func (ShardID) Bytes

func (id ShardID) Bytes() []byte

Bytes returns binary serialization of the shard ID suitable for hashing

func (ShardID) Comparator

func (id ShardID) Comparator() func([]byte) bool

Comparator returns function which checks does the byte slice argument have the prefix which matches the shard ID. NB! It is callers responsibility to not pass shorter slice than the shard id!

func (ShardID) Equal

func (id ShardID) Equal(v ShardID) bool

func (ShardID) Key

func (id ShardID) Key() string

Key is intended to be used where comparable shard ID is needed (ie map key).

func (ShardID) Length

func (id ShardID) Length() uint

Length returns shard ID length in bits.

func (ShardID) MarshalCBOR

func (id ShardID) MarshalCBOR() ([]byte, error)

func (ShardID) MarshalText

func (id ShardID) MarshalText() ([]byte, error)

func (ShardID) Split

func (id ShardID) Split() (ShardID, ShardID)

Split increases shard ID length by one bit and returns the two new IDs. The original shard ID is not altered.

func (ShardID) String

func (id ShardID) String() (s string)

func (*ShardID) UnmarshalCBOR

func (id *ShardID) UnmarshalCBOR(data []byte) (err error)

func (*ShardID) UnmarshalText

func (id *ShardID) UnmarshalText(src []byte) error

type ShardTree

type ShardTree map[string][]byte // ShardID.Key -> hash(IR, TRh)

func CreateShardTree

func CreateShardTree(scheme ShardingScheme, states []ShardTreeInput, algo crypto.Hash) (ShardTree, error)

"states" must contain record for each shard in the "scheme".

func (ShardTree) Certificate

func (tree ShardTree) Certificate(shardID ShardID) (ShardTreeCertificate, error)

Certificate returns Shard Tree Certificate for the shard.

func (ShardTree) RootHash

func (tree ShardTree) RootHash() []byte

type ShardTreeCertificate

type ShardTreeCertificate struct {
	Shard         ShardID
	SiblingHashes [][]byte
	// contains filtered or unexported fields
}

func (ShardTreeCertificate) ComputeCertificateHash

func (cert ShardTreeCertificate) ComputeCertificateHash(IR *InputRecord, TRHash []byte, algo crypto.Hash) ([]byte, error)

ComputeCertificateHash implements the "Compute Shard Tree Certificate" algorithm. Input:

IR - input record of the shard
TRHash - hash of the TechnicalRecord

Output: Root hash

func (ShardTreeCertificate) IsValid

func (cert ShardTreeCertificate) IsValid() error

type ShardTreeInput

type ShardTreeInput struct {
	Shard  ShardID
	IR     *InputRecord
	TRHash []byte // hash of TechnicalRecord
}

ShardTreeInput is source data for leaf node in a shard tree

type ShardingScheme

type ShardingScheme []ShardID

func (ShardingScheme) All

func (sh ShardingScheme) All() iter.Seq[ShardID]

All returns iterator over all shard IDs in the sharding scheme.

For a single shard scheme (empty list) single empty shard ID is returned.

func (ShardingScheme) IsValid

func (sh ShardingScheme) IsValid() error

type SignatureMap

type SignatureMap = map[string]hex.Bytes

type StateLock

type StateLock struct {
	ExecutionPredicate []byte // predicate for executing state locked Tx
	RollbackPredicate  []byte // predicate for discarding state locked Tx
	// contains filtered or unexported fields
}

func (StateLock) IsValid

func (s StateLock) IsValid() error

type StateLockProofSigData

type StateLockProofSigData struct {
	Version ABVersion
	Payload
	// contains filtered or unexported fields
}

type StateTreeCert

type StateTreeCert struct {
	LeftSummaryHash   hex.Bytes            `json:"leftSummaryHash"`
	LeftSummaryValue  uint64               `json:"leftSummaryValue,string"`
	RightSummaryHash  hex.Bytes            `json:"rightSummaryHash"`
	RightSummaryValue uint64               `json:"rightSummaryValue,string"`
	Path              []*StateTreePathItem `json:"path"`
	// contains filtered or unexported fields
}

type StateTreePathItem

type StateTreePathItem struct {
	UnitID              UnitID    `json:"unitId"`       // (ι′)
	LogsHash            hex.Bytes `json:"logsHash"`     // (z)
	Value               uint64    `json:"value,string"` // (V)
	SiblingSummaryHash  hex.Bytes `json:"siblingSummaryHash"`
	SiblingSummaryValue uint64    `json:"siblingSummaryValue,string"`
	// contains filtered or unexported fields
}

type StateUnitData

type StateUnitData struct {
	Data RawCBOR
}

func (*StateUnitData) Hash

func (sd *StateUnitData) Hash(hashAlgo crypto.Hash) ([]byte, error)

func (*StateUnitData) UnmarshalData

func (sd *StateUnitData) UnmarshalData(v any) error

type SystemTypeDescriptor

type SystemTypeDescriptor struct {
}

func (*SystemTypeDescriptor) AddToHasher

func (std *SystemTypeDescriptor) AddToHasher(h abhash.Hasher)

type TaggedCBOR

type TaggedCBOR = RawCBOR

type TransactionOrder

type TransactionOrder struct {
	Version     ABVersion
	Payload             // the embedded Payload field is "flattened" in CBOR array
	StateUnlock []byte  // two CBOR data items: [0|1]+[<state lock/rollback predicate input>]
	AuthProof   RawCBOR // transaction type specific signatures/authorisation proofs
	FeeProof    []byte
	// contains filtered or unexported fields
}

func (*TransactionOrder) AuthProofSigBytes

func (t *TransactionOrder) AuthProofSigBytes() ([]byte, error)

func (*TransactionOrder) FeeCreditRecordID

func (t *TransactionOrder) FeeCreditRecordID() []byte

func (*TransactionOrder) FeeProofSigBytes

func (t *TransactionOrder) FeeProofSigBytes() ([]byte, error)

func (*TransactionOrder) GetNetworkID

func (t *TransactionOrder) GetNetworkID() NetworkID

func (*TransactionOrder) GetPartitionID

func (t *TransactionOrder) GetPartitionID() PartitionID

func (*TransactionOrder) GetUnitID

func (t *TransactionOrder) GetUnitID() UnitID

func (*TransactionOrder) GetVersion

func (t *TransactionOrder) GetVersion() ABVersion

func (*TransactionOrder) HasStateLock

func (t *TransactionOrder) HasStateLock() bool

func (*TransactionOrder) Hash

func (t *TransactionOrder) Hash(algorithm crypto.Hash) ([]byte, error)

func (*TransactionOrder) MarshalCBOR

func (t *TransactionOrder) MarshalCBOR() ([]byte, error)

func (*TransactionOrder) MaxFee

func (t *TransactionOrder) MaxFee() uint64

func (*TransactionOrder) ReferenceNumber

func (t *TransactionOrder) ReferenceNumber() []byte

func (*TransactionOrder) SetAttributes

func (t *TransactionOrder) SetAttributes(attr any) error

SetAttributes serializes "attr" and assigns the result to payload's Attributes field. The "attr" is expected to be one of the transaction attribute structs but there is no validation! The TransactionOrder.UnmarshalAttributes can be used to decode the attributes.

func (*TransactionOrder) SetAuthProof

func (t *TransactionOrder) SetAuthProof(authProof any) error

SetAuthProof converts provided authProof struct to CBOR and sets the AuthProof field.

func (*TransactionOrder) StateLockProofSigBytes

func (t *TransactionOrder) StateLockProofSigBytes() ([]byte, error)

func (*TransactionOrder) Timeout

func (t *TransactionOrder) Timeout() uint64

func (*TransactionOrder) UnmarshalAttributes

func (t *TransactionOrder) UnmarshalAttributes(v any) error

func (*TransactionOrder) UnmarshalAuthProof

func (t *TransactionOrder) UnmarshalAuthProof(v any) error

func (*TransactionOrder) UnmarshalCBOR

func (t *TransactionOrder) UnmarshalCBOR(data []byte) error

type TransactionOrderCBOR

type TransactionOrderCBOR = TaggedCBOR

type TransactionRecord

type TransactionRecord struct {
	Version          ABVersion
	TransactionOrder TransactionOrderCBOR
	ServerMetadata   *ServerMetadata
	// contains filtered or unexported fields
}

TransactionRecord is a transaction order with "server-side" metadata added to it. TransactionRecord is a structure that is added to the block.

func (*TransactionRecord) Bytes

func (t *TransactionRecord) Bytes() ([]byte, error)

func (*TransactionRecord) GetActualFee

func (t *TransactionRecord) GetActualFee() uint64

func (*TransactionRecord) GetTransactionOrderV1

func (t *TransactionRecord) GetTransactionOrderV1() (*TransactionOrder, error)

func (*TransactionRecord) GetVersion

func (t *TransactionRecord) GetVersion() ABVersion

func (*TransactionRecord) Hash

func (t *TransactionRecord) Hash(algorithm crypto.Hash) ([]byte, error)

func (*TransactionRecord) IsSuccessful

func (t *TransactionRecord) IsSuccessful() bool

func (*TransactionRecord) IsValid

func (t *TransactionRecord) IsValid() error

func (*TransactionRecord) MarshalCBOR

func (t *TransactionRecord) MarshalCBOR() ([]byte, error)

func (*TransactionRecord) TargetUnits

func (t *TransactionRecord) TargetUnits() []UnitID

func (*TransactionRecord) TxStatus

func (t *TransactionRecord) TxStatus() TxStatus

func (*TransactionRecord) UnmarshalCBOR

func (t *TransactionRecord) UnmarshalCBOR(data []byte) error

func (*TransactionRecord) UnmarshalProcessingDetails

func (t *TransactionRecord) UnmarshalProcessingDetails(v any) error

type TxProof

type TxProof struct {
	Version            ABVersion
	BlockHeaderHash    []byte
	Chain              []*GenericChainItem
	UnicityCertificate TaggedCBOR
	// contains filtered or unexported fields
}

TxProof is a transaction execution proof.

func (*TxProof) GetVersion

func (p *TxProof) GetVersion() ABVersion

func (*TxProof) IsValid

func (p *TxProof) IsValid() error

func (*TxProof) MarshalCBOR

func (p *TxProof) MarshalCBOR() ([]byte, error)

func (*TxProof) UnmarshalCBOR

func (p *TxProof) UnmarshalCBOR(data []byte) error

type TxRecordProof

type TxRecordProof struct {
	TxRecord *TransactionRecord
	TxProof  *TxProof
	// contains filtered or unexported fields
}

func NewTxRecordProof

func NewTxRecordProof(block *Block, txIndex int, algorithm crypto.Hash) (*TxRecordProof, error)

func (*TxRecordProof) ActualFee

func (t *TxRecordProof) ActualFee() uint64

func (*TxRecordProof) GetTransactionOrderV1

func (t *TxRecordProof) GetTransactionOrderV1() (*TransactionOrder, error)

func (*TxRecordProof) IsValid

func (t *TxRecordProof) IsValid() error

func (*TxRecordProof) TxStatus

func (t *TxRecordProof) TxStatus() TxStatus

type TxStatus

type TxStatus uint64
const (
	// TxStatusFailed is the status code of a transaction if execution failed.
	TxStatusFailed TxStatus = 0
	// TxStatusSuccessful is the status code of a transaction if execution succeeded.
	TxStatusSuccessful TxStatus = 1
	// TxErrOutOfGas tx execution run out of gas, try with bigger 'MaxTransactionFee'
	TxErrOutOfGas TxStatus = 2
)

type UnicityCertificate

type UnicityCertificate struct {
	Version                ABVersion               `json:"version"`
	InputRecord            *InputRecord            `json:"inputRecord"`
	TRHash                 hex.Bytes               `json:"trHash"` // hash of the TechnicalRecord
	ShardTreeCertificate   ShardTreeCertificate    `json:"shardTreeCertificate"`
	UnicityTreeCertificate *UnicityTreeCertificate `json:"unicityTreeCertificate"`
	UnicitySeal            *UnicitySeal            `json:"unicitySeal"`
	// contains filtered or unexported fields
}

func (*UnicityCertificate) GetFeeSum

func (x *UnicityCertificate) GetFeeSum() uint64

func (*UnicityCertificate) GetPreviousStateHash

func (x *UnicityCertificate) GetPreviousStateHash() []byte

func (*UnicityCertificate) GetRootRoundNumber

func (x *UnicityCertificate) GetRootRoundNumber() uint64

func (*UnicityCertificate) GetRoundNumber

func (x *UnicityCertificate) GetRoundNumber() uint64

func (*UnicityCertificate) GetStateHash

func (x *UnicityCertificate) GetStateHash() []byte

func (*UnicityCertificate) GetSummaryValue

func (x *UnicityCertificate) GetSummaryValue() []byte

func (*UnicityCertificate) GetVersion

func (x *UnicityCertificate) GetVersion() ABVersion

func (*UnicityCertificate) Hash

func (x *UnicityCertificate) Hash(hash crypto.Hash) ([]byte, error)

func (*UnicityCertificate) IsDuplicate

func (x *UnicityCertificate) IsDuplicate(prevUC *UnicityCertificate) bool

func (*UnicityCertificate) IsRepeat

func (x *UnicityCertificate) IsRepeat(prevUC *UnicityCertificate) (bool, error)

func (*UnicityCertificate) IsSuccessor

func (x *UnicityCertificate) IsSuccessor(prevUC *UnicityCertificate) bool

func (*UnicityCertificate) IsValid

func (x *UnicityCertificate) IsValid(algorithm crypto.Hash, partitionID PartitionID, systemDescriptionHash []byte) error

func (*UnicityCertificate) MarshalCBOR

func (x *UnicityCertificate) MarshalCBOR() ([]byte, error)

func (*UnicityCertificate) UnmarshalCBOR

func (x *UnicityCertificate) UnmarshalCBOR(data []byte) error

func (*UnicityCertificate) Verify

func (x *UnicityCertificate) Verify(tb RootTrustBase, algorithm crypto.Hash, partitionID PartitionID, systemDescriptionHash []byte) error

type UnicityCertificateValidator

type UnicityCertificateValidator interface {
	Validate(uc *UnicityCertificate) error
}

type UnicitySeal

type UnicitySeal struct {
	Version              ABVersion    `json:"version"`
	RootChainRoundNumber uint64       `json:"rootChainRoundNumber"`
	Timestamp            uint64       `json:"timestamp"`
	PreviousHash         hex.Bytes    `json:"previousHash"`
	Hash                 hex.Bytes    `json:"hash"`
	Signatures           SignatureMap `json:"signatures"`
	// contains filtered or unexported fields
}

func (*UnicitySeal) AddToHasher

func (x *UnicitySeal) AddToHasher(hasher abhash.Hasher)

AddToHasher - add all UC data including signature bytes for hash calculation

func (*UnicitySeal) GetVersion

func (x *UnicitySeal) GetVersion() ABVersion

func (*UnicitySeal) IsValid

func (x *UnicitySeal) IsValid() error

func (*UnicitySeal) MarshalCBOR

func (x *UnicitySeal) MarshalCBOR() ([]byte, error)

func (UnicitySeal) SigBytes

func (x UnicitySeal) SigBytes() ([]byte, error)

SigBytes - serialize everything except signatures (used for sign and verify)

func (*UnicitySeal) Sign

func (x *UnicitySeal) Sign(id string, signer crypto.Signer) error

func (*UnicitySeal) UnmarshalCBOR

func (x *UnicitySeal) UnmarshalCBOR(b []byte) error

func (*UnicitySeal) Verify

func (x *UnicitySeal) Verify(tb RootTrustBase) error

type UnicityTree

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

func NewUnicityTree

func NewUnicityTree(hashAlgorithm crypto.Hash, data []*UnicityTreeData) (*UnicityTree, error)

NewUnicityTree creates a new unicity tree with given partitions.

NB! Sorts the "data" slice without making copy of it!

func (*UnicityTree) Certificate

func (u *UnicityTree) Certificate(partition PartitionID) (*UnicityTreeCertificate, error)

Certificate returns an unicity tree certificate for given system identifier.

func (*UnicityTree) RootHash

func (u *UnicityTree) RootHash() []byte

type UnicityTreeCertificate

type UnicityTreeCertificate struct {
	Version   ABVersion       `json:"version"`
	Partition PartitionID     `json:"partitionIdentifier"`
	HashSteps []*imt.PathItem `json:"hashSteps"`
	PDRHash   hex.Bytes       `json:"partitionDescriptionHash"`
	// contains filtered or unexported fields
}

func (*UnicityTreeCertificate) AddToHasher

func (utc *UnicityTreeCertificate) AddToHasher(hasher abhash.Hasher)

func (*UnicityTreeCertificate) EvalAuthPath

func (utc *UnicityTreeCertificate) EvalAuthPath(shardTreeRoot []byte, hashAlgorithm crypto.Hash) ([]byte, error)

EvalAuthPath aka Compute Unicity Tree Certificate.

The shardTreeRoot is output of the CompShardTreeCert function.

func (*UnicityTreeCertificate) GetVersion

func (utc *UnicityTreeCertificate) GetVersion() ABVersion

func (*UnicityTreeCertificate) IsValid

func (utc *UnicityTreeCertificate) IsValid(partition PartitionID, systemDescriptionHash []byte) error

func (*UnicityTreeCertificate) MarshalCBOR

func (utc *UnicityTreeCertificate) MarshalCBOR() ([]byte, error)

func (*UnicityTreeCertificate) UnmarshalCBOR

func (utc *UnicityTreeCertificate) UnmarshalCBOR(data []byte) error

type UnicityTreeData

type UnicityTreeData struct {
	Partition     PartitionID
	ShardTreeRoot []byte // root hash of the partition shard tree
	PDRHash       []byte // PartitionDescriptionRecord hash
}

func (*UnicityTreeData) AddToHasher

func (t *UnicityTreeData) AddToHasher(hasher abhash.Hasher)

func (*UnicityTreeData) Key

func (t *UnicityTreeData) Key() []byte

type UnitData

type UnitData interface {
	Write(hasher abhash.Hasher)
	SummaryValueInput() uint64
	Copy() UnitData
	Owner() []byte
}

UnitData is a generic data type for the unit state.

type UnitDataAndProof

type UnitDataAndProof struct {
	UnitData *StateUnitData
	Proof    *UnitStateProof
	// contains filtered or unexported fields
}

func (*UnitDataAndProof) UnmarshalUnitData

func (up *UnitDataAndProof) UnmarshalUnitData(v any) error

type UnitID

type UnitID []byte

UnitID is the extended identifier, combining the type and the unit identifiers.

func NewUnitID

func NewUnitID(unitIDLength int, shardPart []byte, unitPart []byte, typePart []byte) UnitID

NewUnitID creates a new UnitID consisting of a shardPart, unitPart and typePart.

func (UnitID) Compare

func (uid UnitID) Compare(key UnitID) int

func (UnitID) Eq

func (uid UnitID) Eq(id UnitID) bool

func (UnitID) HasType

func (uid UnitID) HasType(typePart []byte) bool

func (UnitID) MarshalText

func (uid UnitID) MarshalText() ([]byte, error)

func (UnitID) String

func (uid UnitID) String() string

func (*UnitID) UnmarshalText

func (uid *UnitID) UnmarshalText(src []byte) error

type UnitStateProof

type UnitStateProof struct {
	Version            ABVersion      `json:"version"`
	UnitID             UnitID         `json:"unitId"`
	UnitValue          uint64         `json:"unitValue,string"`
	UnitLedgerHash     hex.Bytes      `json:"unitLedgerHash"`
	UnitTreeCert       *UnitTreeCert  `json:"unitTreeCert"`
	StateTreeCert      *StateTreeCert `json:"stateTreeCert"`
	UnicityCertificate TaggedCBOR     `json:"unicityCert"`
	// contains filtered or unexported fields
}

func (*UnitStateProof) CalculateStateTreeOutput

func (u *UnitStateProof) CalculateStateTreeOutput(algorithm crypto.Hash) ([]byte, uint64, error)

func (*UnitStateProof) GetVersion

func (u *UnitStateProof) GetVersion() ABVersion

func (*UnitStateProof) MarshalCBOR

func (u *UnitStateProof) MarshalCBOR() ([]byte, error)

func (*UnitStateProof) UnmarshalCBOR

func (u *UnitStateProof) UnmarshalCBOR(data []byte) error

type UnitTreeCert

type UnitTreeCert struct {
	TransactionRecordHash hex.Bytes      `json:"txrHash"`  // t
	UnitDataHash          hex.Bytes      `json:"dataHash"` // s
	Path                  []*mt.PathItem `json:"path"`
	// contains filtered or unexported fields
}

type Versioned

type Versioned interface {
	GetVersion() ABVersion
}

Versioned interface is used by the structs that require versioning. By our convention, the version is the first field of the struct with type ABVersion. Version must be greater than 0.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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