primitives

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

This module contains the definition and implementation of the Block structure and its methods

This module contains the functions used to serialize and deserialize primitive type to binary gob data

This module contains the definition and implementation of the Transaction struct and its methods

This module contains the definition and implementation of the smaller component structures such as TXI, TXO and Address.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	// Represents the bytes value of the address
	Bytes []byte

	// Represents the string value of the address
	String string

	// Represents the version/weave prefix of the address
	Prefix byte

	// Represents the adddress checksum
	Checksum Hash

	// Represents the hash of the public key of the address
	PublicKeyHash Hash
}

A struct that represents the Address of a User/Wallet

func NewAddress

func NewAddress(address string) (*Address, error)

A constructor function that generates and returns a new Address object from a given address string.

func (*Address) IsValid

func (addr *Address) IsValid() bool

A method of Address that checks if the address checksum is valid and returns a boolean

type Block

type Block struct {
	// Represents the Block Header
	BlockHeader

	// Represents the Block Height
	BlockHeight int

	// Represents the no.of Transactions in the Block
	TXCount int

	// Represents the list of Transactions in the Block
	TXList []*Transaction

	// Represents the address of the Block origin (coinbase address)
	BlockOrigin Address

	// Represents the Hash of the Block Header
	BlockHash Hash
}

A structure that represents a single Block on the Blockchain

func BlockDeserialize

func BlockDeserialize(gobdata Gob) *Block

A function to deserialize a gob of bytes into a Block

type BlockHeader

type BlockHeader struct {
	// Represents the consensus parameters of the Block
	ConsensusHeader

	// Represents the hash of the previous Block
	Priori Hash

	// Represents the timestamp of the Block at the point of creation
	Timestamp int64

	// Represent the merkle root of transactions on the Block
	MerkleRoot Hash

	// Represents the weave network of the Block
	BlockWeave []byte

	// Represents the software version of Block Generator
	Version []byte
}

A structure that represents the header of a Block

func BlockHeaderDeserialize

func BlockHeaderDeserialize(gobdata Gob) *BlockHeader

A function to deserialize a gob of bytes into a BlockHeader

type ConsensusHeader

type ConsensusHeader interface {
	Mint(*Block) error
	Validate(*Block) bool
}

An interface for all types of consensus headers

type Gob

type Gob []byte

A type alias for a byte slice that represents a gob of data

func BlockHeaderSerialize

func BlockHeaderSerialize(header *BlockHeader) Gob

A function to serialize a BlockHeader into gob of bytes

func BlockSerialize

func BlockSerialize(block *Block) Gob

A function to serialize a Block into gob of bytes

func TXOListSerialize

func TXOListSerialize(txos *TXOList) Gob

A function to serialize a TXOList into gob of bytes

func TxnSerialize

func TxnSerialize(txn *Transaction) Gob

A function to serialize a Transaction into a gob of bytes

type Hash

type Hash []byte

A type alias for a byte slice that represents a hash

type PublicKey

type PublicKey []byte

A type alias for a byte slice that represents a wallet public key

type TXI

type TXI struct {
	// Represents the transaction ID of which the reference output is a part
	ID Hash

	// Represents the index of reference output in the transaction
	OutIndex int

	// Represents the signature of the transaction
	Signature []byte

	// Represents the public key of the sending address
	PublicKey PublicKey
}

A structure that represents the inputs in a transaction which are really just references to previous outputs

func (*TXI) CheckKey

func (txi *TXI) CheckKey(publickeyhash Hash) bool

A method of TxInput that checks if the input public key is valid for a given public key hash

type TXIList

type TXIList []TXI

A type alias for a slice of transaction inputs

type TXO

type TXO struct {
	// Represents the token value of a given transaction output
	Value int

	// Represents the hash of the public key of the recieving address
	PublicKeyHash Hash
}

A structure that represents the outputs in a transaction

func (*TXO) CheckLock

func (txo *TXO) CheckLock(lockhash []byte) bool

A method of TxOutput that checks if the ouput key hash is valid for a given locking hash

func (*TXO) Lock

func (txo *TXO) Lock(address Address)

TODO: needs rework when wallet tools are refactored A method of TxOutput that locks the output for a given address

type TXOList

type TXOList []TXO

A type alias for a slice of transaction outputs

func TXOListDeserialize

func TXOListDeserialize(gobdata Gob) *TXOList

A function to deserialize a gob of bytes into a TXOList

type Transaction

type Transaction struct {
	// Represents the ID of the transaction obtained from its hash
	ID Hash

	// Represents the list of transaction inputs
	Inputs TXIList

	// Represents the list of transaction outputs
	Outputs TXOList
}

A structure that represents a transaction on the Animus Blockchain

func TxnDeserialize

func TxnDeserialize(gobdata Gob) *Transaction

A function to deserialize a gob of bytes into a Transaction

func (*Transaction) GenerateHash

func (txn *Transaction) GenerateHash() Hash

A method of Transaction that generates a hash of the Transaction

func (*Transaction) GenerateSafeCopy

func (txn *Transaction) GenerateSafeCopy() Transaction

A method of Transaction that generates a safe version of the Transaction that does not include the signature and public keys of its transaction inputs

func (*Transaction) GenerateString

func (txn *Transaction) GenerateString() string

A method of Transaction that generates the string representation of a transaction and all its inputs and outputs. TODO: NEEDS REWORK FOR FORMATTING

func (*Transaction) IsCoinbaseTxn

func (txn *Transaction) IsCoinbaseTxn() bool

A method of Transaction that checks if it is a Coinbase Transaction

Jump to

Keyboard shortcuts

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