external

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 7 Imported by: 33

Documentation

Index

Constants

View Source
const DomainHashSize = 32

DomainHashSize of array used to store hashes.

View Source
const DomainSubnetworkIDSize = 20

DomainSubnetworkIDSize is the size of the array used to store subnetwork IDs.

Variables

This section is empty.

Functions

func HashesEqual

func HashesEqual(a, b []*DomainHash) bool

HashesEqual returns whether the given hash slices are equal.

Types

type BaseBlockHeader

type BaseBlockHeader interface {
	Version() uint16
	Blockheight() uint64
	BlockHash() *DomainHash
	Previoushash() *DomainHash
	Merkleroothash() *DomainHash
	DirectParents() BlockLevelParents
	MetBlock() *DomainHash
	MegaBlock() *DomainHash
	ChildBlocks() []BlockLevelChildern
	UTXOCommitment() *DomainHash
	TimeInMilliseconds() int64
	BlockLevel(maxBlockLevel int) int
	Parents() []BlockLevelParents
	Bits() uint64
	Nonce() uint64
	UtxoCommitment() []byte
	Btype() int
}

BaseBlockHeader represents the header part of a MET block

type BlockAdded

type BlockAdded struct {
	Block *DomainBlock
}

BlockAdded is an event raised by consensus when a block was added to the dag

type BlockHeader

type BlockHeader interface {
	BaseBlockHeader
	ToMutable() MutableBlockHeader
}

type BlockInfo

type BlockInfo struct {
	Exists         bool
	BlockStatus    BlockStatus
	BlueScore      uint64
	BlueWork       *big.Int
	SelectedParent *DomainHash
	MergeSetBlues  []*DomainHash
	MergeSetReds   []*DomainHash
}

BlockInfo contains various information about a specific block

type BlockLevelChildern

type BlockLevelChildern []*DomainHash

func CloneChildren

func CloneChildren(parents []BlockLevelChildern) []BlockLevelChildern

CloneParents creates a clone of the given BlockLevelParents slice

func (BlockLevelChildern) Clone

Clone creates a clone of this BlockLevelParents

type BlockLevelParents

type BlockLevelParents []*DomainHash

func CloneParents

func CloneParents(parents []BlockLevelParents) []BlockLevelParents

CloneParents creates a clone of the given BlockLevelParents slice

func (BlockLevelParents) Clone

Clone creates a clone of this BlockLevelParents

type BlockLocator

type BlockLocator []*DomainHash

type BlockMetDataHashPair

type BlockMetDataHashPair struct {
	Hash        *DomainHash
	MetGDagData *MetGDagData
}

BlockGHOSTDAGDataHashPair is a pair of a block hash and its ghostdag data

type BlockSent

type BlockSent struct {
	Block *DomainBlock
}

BlockAdded is an event raised by consensus when a block was added to the dag

type BlockStatus

type BlockStatus byte

BlockStatus represents the validation state of the block.

const (
	// StatusInvalid indicates that the block is invalid.
	StatusInvalid BlockStatus = iota

	// StatusUTXOValid indicates the block is valid from any UTXO related aspects and has passed all the other validations as well.
	StatusUTXOValid

	// StatusUTXOPendingVerification indicates that the block is pending verification against its past UTXO-Set, either
	// because it was not yet verified since the block was never in the selected parent chain, or if the
	// block violates finality.
	StatusUTXOPendingVerification

	// StatusDisqualifiedFromChain indicates that the block is not eligible to be a selected parent.
	StatusDisqualifiedFromChain

	// StatusHeaderOnly indicates that the block transactions are not held (pruned or wasn't added yet)
	StatusHeaderOnly
)

type BlockWithTrustedData

type BlockWithTrustedData struct {
	Block       *DomainBlock
	MetblockDAA []*TrustedDataDataMETBlockHeader
	MetDagData  []*BlockMetDataHashPair
}

type Consensus

type Consensus interface {
	Init(skipAddingGenesis bool) error
	//Needed for Mining
	BuildBlockTemplate(coinbaseData *DomainCoinbaseData) (*DomainBlockTemplate, error)
	BuildBlock(block *TempBlock) (*TempBlock, error)
}

type ConsensusEvent

type ConsensusEvent interface {
	// contains filtered or unexported methods
}

ConsensusEvent is an interface type that is implemented by all events raised by consensus

type DomainBlock

type DomainBlock struct {
	Header       BlockHeader
	Transactions []*DomainTransaction
}

DomainBlock represents a Metchain block

func (*DomainBlock) Clone

func (block *DomainBlock) Clone() *DomainBlock

Clone returns a clone of DomainBlock

type DomainBlockTemplate

type DomainBlockTemplate struct {
	Block        *DomainBlock
	CoinbaseData *DomainCoinbaseData

	IsNearlySynced bool
}

DomainBlockTemplate contains a Block plus metadata related to its generation

type DomainCoinbaseData

type DomainCoinbaseData struct {
	ScriptPublicKey *ScriptPublicKey
	ExtraData       []byte
}

DomainCoinbaseData contains data by which a coinbase transaction is built

func AddressToConbaseData

func AddressToConbaseData(address mconfig.Address, data string) *DomainCoinbaseData

func (*DomainCoinbaseData) Equal

func (dcd *DomainCoinbaseData) Equal(other *DomainCoinbaseData) bool

type DomainHash

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

DomainHash is the domain representation of a Hash

func CloneHashes

func CloneHashes(hashes []*DomainHash) []*DomainHash

CloneHashes returns a clone of the given hashes slice. Note: since DomainHash is a read-only type, the clone is shallow

func NewDomainHashFromByteArray

func NewDomainHashFromByteArray(hashBytes *[DomainHashSize]byte) *DomainHash

NewDomainHashFromByteArray constructs a new DomainHash out of a byte array

func NewDomainHashFromByteSlice

func NewDomainHashFromByteSlice(hashBytes []byte) (*DomainHash, error)

NewDomainHashFromByteSlice constructs a new DomainHash out of a byte slice. Returns an error if the length of the byte slice is not exactly `DomainHashSize`

func NewDomainHashFromString

func NewDomainHashFromString(hashString string) (*DomainHash, error)

NewDomainHashFromString constructs a new DomainHash out of a hex-encoded string. Returns an error if the length of the string is not exactly `DomainHashSize * 2`

func NewZeroHash

func NewZeroHash() *DomainHash

NewZeroHash returns a DomainHash that represents the zero value (0x000000...000)

func (*DomainHash) ByteArray

func (hash *DomainHash) ByteArray() *[DomainHashSize]byte

ByteArray returns the bytes in this hash represented as a byte array. The hash bytes are cloned, therefore it is safe to modify the resulting array.

func (*DomainHash) ByteSlice

func (hash *DomainHash) ByteSlice() []byte

ByteSlice returns the bytes in this hash represented as a byte slice. The hash bytes are cloned, therefore it is safe to modify the resulting slice.

func (*DomainHash) Equal

func (hash *DomainHash) Equal(other *DomainHash) bool

Equal returns whether hash equals to other

func (*DomainHash) Less

func (hash *DomainHash) Less(other *DomainHash) bool

Less returns true if hash is less than other

func (*DomainHash) LessOrEqual

func (hash *DomainHash) LessOrEqual(other *DomainHash) bool

LessOrEqual returns true if hash is smaller or equal to other

func (DomainHash) String

func (hash DomainHash) String() string

String returns the Hash as the hexadecimal string of the hash.

type DomainOutpoint

type DomainOutpoint struct {
	TransactionID DomainTransactionID
	Index         uint32
}

DomainOutpoint represents a Metchain transaction outpoint

type DomainSubnetworkID

type DomainSubnetworkID [DomainSubnetworkIDSize]byte

DomainSubnetworkID is the domain representation of a Subnetwork ID

func (*DomainSubnetworkID) Clone

Clone returns a clone of DomainSubnetworkID

func (*DomainSubnetworkID) Equal

func (id *DomainSubnetworkID) Equal(other *DomainSubnetworkID) bool

Equal returns whether id equals to other

func (DomainSubnetworkID) String

func (id DomainSubnetworkID) String() string

String stringifies a subnetwork ID.

type DomainTransaction

type DomainTransaction struct {
	Version uint16
	Inputs  []*DomainTransactionInput

	LockTime uint64

	Payload []byte

	Fee uint64

	ID *DomainTransactionID
}

DomainTransaction represents a Metchain transaction

type DomainTransactionID

type DomainTransactionID DomainHash

DomainTransactionID represents the ID of a Metchain transaction

func (*DomainTransactionID) ByteSlice

func (id *DomainTransactionID) ByteSlice() []byte

ByteSlice returns the bytes in this transactionID represented as a byte slice. The transactionID bytes are cloned, therefore it is safe to modify the resulting slice.

type DomainTransactionInput

type DomainTransactionInput struct {
	PreviousOutpoint DomainOutpoint
	SignatureScript  []byte
	Sequence         uint64
	SigOpCount       byte

	UTXOEntry UTXOEntry
}

DomainTransactionInput represents a Metchain transaction input

type MType

type MType byte

type MetGDagData

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

func NewMETGBlockData

func NewMETGBlockData(

	selectedParent *DomainHash,
) *MetGDagData

NewBlockGHOSTDAGData creates a new instance of BlockGHOSTDAGData

func (*MetGDagData) SelectedParent

func (mgdb *MetGDagData) SelectedParent() *DomainHash

SelectedParent returns the SelectedParent of the block

type MutableBlockHeader

type MutableBlockHeader interface {
	BaseBlockHeader
	ToImmutable() BlockHeader
	SetNonce(nonce uint64)
	SetTimeInMilliseconds(timeInMilliseconds int64)
	SetHashMerkleRoot(hashMerkleRoot *DomainHash)
}

type MutableUTXODiff

type MutableUTXODiff interface {
	ToImmutable() UTXODiff

	WithDiff(other UTXODiff) (UTXODiff, error)
	DiffFrom(other UTXODiff) (UTXODiff, error)
	ToAdd() UTXOCollection
	ToRemove() UTXOCollection

	WithDiffInPlace(other UTXODiff) error
	AddTransaction(transaction *DomainTransaction, blockDAAScore uint64) error
}

MutableUTXODiff represents a UTXO-Diff that can be mutated

type OutpointAndUTXOEntryPair

type OutpointAndUTXOEntryPair struct {
	Outpoint  *DomainOutpoint
	UTXOEntry UTXOEntry
}

OutpointAndUTXOEntryPair is an outpoint along with its respective UTXO entry

type ReadOnlyUTXOSetIterator

type ReadOnlyUTXOSetIterator interface {
	First() bool
	Next() bool
	Get() (outpoint *DomainOutpoint, utxoEntry UTXOEntry, err error)
	Close() error
}

type ScriptPublicKey

type ScriptPublicKey struct {
	Script  []byte
	Version []byte
}

represents a Metchain ScriptPublicKey

func (*ScriptPublicKey) Equal

func (spk *ScriptPublicKey) Equal(other *ScriptPublicKey) bool

Equal returns whether spk equals to other

type SelectedChainPath

type SelectedChainPath struct {
	Added   []*DomainHash
	Removed []*DomainHash
}

SelectedChainPath is a path the of the selected chains between two blocks.

type SyncInfo

type SyncInfo struct {
	HeaderCount uint64
	BlockCount  uint64
}

SyncInfo holds info about the current sync state of the consensus

type TempBlock

type TempBlock struct {
	Height       uint64
	Timestamp    int64
	Nonce        uint64
	PreviousHash [32]byte //As per the Hash size
	Megablock    [32]byte
	Metblock     [32]byte
	Transactions []*TempTransaction
	CurrentHash  [32]byte
	Bits         uint64
}

func (*TempBlock) MarshalJSON

func (b *TempBlock) MarshalJSON() ([]byte, error)

type TempTransaction

type TempTransaction struct {
	SenderBlockchainAddress    string
	RecipientBlockchainAddress string
	Txtype                     int8
	Value                      float32
	Txhash                     [32]byte
	Timestamp                  int64
	Txstatus                   int8
}

func (*TempTransaction) MarshalJSON

func (t *TempTransaction) MarshalJSON() ([]byte, error)

type TrustedDataDataMETBlockHeader

type TrustedDataDataMETBlockHeader struct {
	Header      BlockHeader
	MetGDagData *MetGDagData
}

TrustedDataDataDAAHeader is a block that belongs to BlockWithTrustedData.DAAWindow

type UTXOCollection

type UTXOCollection interface {
	Iterator() ReadOnlyUTXOSetIterator
	Get(outpoint *DomainOutpoint) (UTXOEntry, bool)
	Contains(outpoint *DomainOutpoint) bool
	Len() int
}

UTXOCollection represents a collection of UTXO entries, indexed by their outpoint

type UTXODiff

type UTXODiff interface {
	ToAdd() UTXOCollection
	ToRemove() UTXOCollection
	WithDiff(other UTXODiff) (UTXODiff, error)
	DiffFrom(other UTXODiff) (UTXODiff, error)
	Reversed() UTXODiff
	CloneMutable() MutableUTXODiff
}

UTXODiff represents the diff between two UTXO sets

type UTXOEntry

type UTXOEntry interface {
	Amount() uint64                    // Utxo amount in Sompis
	ScriptPublicKey() *ScriptPublicKey // The public key script for the output.
	BlockDAAScore() uint64             // Daa score of the block accepting the tx.
	IsCoinbase() bool
	Equal(other UTXOEntry) bool
}

UTXOEntry houses details about an individual transaction output in a utxo set such as whether or not it was contained in a coinbase tx, the daa score of the block that accepts the tx, its public key script, and how much it pays.

type VirtualChangeSet

type VirtualChangeSet struct {
	VirtualSelectedParentChainChanges *SelectedChainPath
	VirtualUTXODiff                   UTXODiff
	VirtualParents                    []*DomainHash
	VirtualSelectedParentBlueScore    uint64
	VirtualDAAScore                   uint64
}

VirtualChangeSet is an event raised by consensus when virtual changes

Jump to

Keyboard shortcuts

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