blockchain

package
v0.0.0-...-8d363c1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DIFFICULTY_INCREASE_STEP = 1024
View Source
const PEER_NETWORK_VERSION = "v0.1"
View Source
const SIZE_OF_HEAD = 2 + 4 + 64 + 4 + 1
View Source
const START_DIFFICULTY = 8

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Head BlockHead
	Body BlockBody
	Tail BlockTail
}

func CreateBlock

func CreateBlock(index uint16, prevHash []byte, flag BodyFlags, message []byte) Block

func Deserialization

func Deserialization(serial []byte) Block

func (Block) CaculateHash

func (block Block) CaculateHash() []byte

func (Block) IsMined

func (block Block) IsMined() bool

func (Block) IsValid

func (block Block) IsValid() bool

func (*Block) MineBlock

func (block *Block) MineBlock()

func (Block) SerializationWithTail

func (block Block) SerializationWithTail() []byte

func (Block) SerializationWithoutTail

func (block Block) SerializationWithoutTail() []byte

type BlockBody

type BlockBody struct {
	Flag    BodyFlags
	Message []byte
}

type BlockHead

type BlockHead struct {
	Index      uint16
	CreatedAt  uint32
	PrevHash   []byte
	Nonce      uint32
	Difficulty uint8
}

type BlockTail

type BlockTail struct {
	CurrHash []byte
}

type BodyFlags

type BodyFlags byte
const (
	GENESIS BodyFlags = 0
	PEER    BodyFlags = 1
	DATA    BodyFlags = 2
)

type BodyStructure

type BodyStructure struct {
	Flag    string `json:"flag"`
	Message string `json:"message"`
}

type Chain

type Chain struct {
	Blocks []Block
}

func CreateChain

func CreateChain() Chain

func Load

func Load(path string) Chain

func (*Chain) AddBlock

func (chain *Chain) AddBlock(newBlock Block)

func (*Chain) AddPeerBlock

func (chain *Chain) AddPeerBlock(peer Peer)

func (*Chain) AddStringBlock

func (chain *Chain) AddStringBlock(data string)

func (*Chain) CreateGenesisBlock

func (chain *Chain) CreateGenesisBlock()

func (*Chain) CreatePeer

func (chain *Chain) CreatePeer(port int) Peer

func (Chain) Drop

func (chain Chain) Drop(path string)

func (Chain) GetLatestBlock

func (chain Chain) GetLatestBlock() Block

func (Chain) GetPeers

func (chain Chain) GetPeers() []Peer

func (Chain) IsValid

func (chain Chain) IsValid() bool

func (Chain) Save

func (chain Chain) Save(path string)

type Peer

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

func (*Peer) Open

func (peer *Peer) Open()

type PeerData

type PeerData struct {
	Address string `json:"address"`
	Port    int    `json:"port"`
	Version string `json:"version"`
}

Jump to

Keyboard shortcuts

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