blockchain

package
v0.0.0-...-910d698 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DIFFICULTY = 12

Variables

This section is empty.

Functions

func CalHashSha256

func CalHashSha256(d []byte) []byte

func CalMerkleNodeHash

func CalMerkleNodeHash(l, r []byte) []byte

func CalMerkleRootHash

func CalMerkleRootHash(d [][]byte) []byte

Input d : list of hashes not data

func CalMerkleUpperHashs

func CalMerkleUpperHashs(hashes [][]byte) [][]byte

func ProofWork

func ProofWork(b *Block) (int, int, []byte)

func Validate

func Validate(b *Block) bool

Types

type Block

type Block struct {
	Header       BlockHeader
	Transactions []*Transaction
}

func CreateBlock

func CreateBlock(trs []*Transaction, prevhash []byte, height int) *Block

func CreateGenesis

func CreateGenesis(w *wallet.Wallet) *Block

func (*Block) MerkleRoot

func (b *Block) MerkleRoot() []byte

func (*Block) PoW

func (b *Block) PoW()

type BlockHeader

type BlockHeader struct {
	Hash       []byte
	PrvHash    []byte
	MerkleRoot []byte
	Timestamp  int64
	Difficulty int
	Nonce      int
	Height     int
}

func (*BlockHeader) GetHash

func (bh *BlockHeader) GetHash() []byte

type Transaction

type Transaction struct {
	Hash      []byte
	Timestamp int64
	Data      []byte
	Signature []byte
	PubKey    []byte
}

func CreateTransaction

func CreateTransaction(w *wallet.Wallet, d []byte) *Transaction

func (*Transaction) GetHash

func (t *Transaction) GetHash() []byte

func (*Transaction) Verify

func (t *Transaction) Verify() bool

Jump to

Keyboard shortcuts

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