block

package module
v0.0.0-...-2739c2c Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: Apache-2.0 Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(block, other Block) bool

Equal returns true if block is equal to other

func Validate

func Validate(prev, current Block) error

Validate compares two blocks to verify their parent child relationship.

Types

type Basic

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

Basic is the skeleton used to implement a block

func (Basic) Blockhash

func (block Basic) Blockhash() []byte

Blockhash returns this blocks hash

func (Basic) Data

func (block Basic) Data() []byte

Data returns the blocks data

func (Basic) Hash

func (block Basic) Hash() []byte

Hash returns the block's hash

func (Basic) Index

func (block Basic) Index() int

Index returns the index of the block

func (Basic) JSON

func (block Basic) JSON() BlockJSON

BlockJSON returns the block's json structure

func (*Basic) MarshalJSON

func (block *Basic) MarshalJSON() ([]byte, error)

MarshalJSON marshals a block JSON

func (Basic) Parenthash

func (block Basic) Parenthash() []byte

Parenthash returns the parent block's hash

func (Basic) Serialize

func (block Basic) Serialize() ([]byte, error)

Serialize returns the json for a block object

func (Basic) Timestamp

func (block Basic) Timestamp() int64

Timestamp returns the timestamp of the block

func (*Basic) UnmarshalJSON

func (block *Basic) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals a block JSON

type Block

type Block interface {
	Serialize() ([]byte, error)
	Hash() []byte
	JSON() BlockJSON

	Index() int
	Timestamp() int64
	Parenthash() []byte
	Blockhash() []byte
	Data() []byte
	// contains filtered or unexported methods
}

Block the interface used to implement a block

type BlockJSON

type BlockJSON struct {
	Index      int    `json:"index"`
	Timestamp  int64  `json:"timestamp"`
	Data       []byte `json:"data"`
	Parenthash []byte `json:"parentHash"`
	Blockhash  []byte `json:"blockhash,omitempty"`
}

func (BlockJSON) Block

func (block BlockJSON) Block() Basic

Block returns the basic block from the JSON structure

type SHA512

type SHA512 struct {
	Basic
}

SHA512 is a block that uses the SHA512 hash

func NewSHA512

func NewSHA512(index int, data []byte, parentHash []byte) *SHA512

NewSHA512 creates a new block using SHA512 hashing

func NewSHA512Genesis

func NewSHA512Genesis() *SHA512

NewGenesis returns a new gensis block hashed with SHA512

Jump to

Keyboard shortcuts

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