blockchain

package
v0.0.0-...-c9960b4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const BENEFICIARY = 100
View Source
const DIFFICULTY = 14

Variables

This section is empty.

Functions

func ToHex

func ToHex(x int64) []byte

func Validate

func Validate(lastBlock, b *Block, state State) bool

func ValidatePow

func ValidatePow(b *Block) bool

验证是否满足难度条件

func VerifySig

func VerifySig(signature, pubKeyHash, data []byte) bool

验证交易输入的签名

Types

type Block

type Block struct {
	Hash         []byte
	ParentHash   []byte
	StateRoot    []byte
	TxRoot       []byte
	ReceiptRoot  []byte
	Difficulty   int
	Timestamp    int64
	Height       int
	Transactions []*Transaction
	Nonce        int
}

func CreateBlock

func CreateBlock(parentHash, stateRoot, txRoot, receiptRoot []byte, diff, height int) *Block

func Genesis

func Genesis() *Block

type BlockChain

type BlockChain struct {
	Blocks []*Block
	State  State
}

func InitBlockChain

func InitBlockChain() *BlockChain

func (*BlockChain) AddBlock

func (chain *BlockChain) AddBlock(b *Block)

没有父Hash的Block

type Pow

type Pow struct {
	Block  *Block
	Target *big.Int
}

func NewPow

func NewPow(block *Block) *Pow

func (*Pow) InitData

func (pow *Pow) InitData(nonce int) []byte

type State

type State struct {
}

type Transaction

type Transaction struct {
	Id    []byte
	From  []byte
	To    []byte
	Value int
	Data  []byte
	Sign  []byte

	Type TxType

	Signature []byte
	// contains filtered or unexported fields
}

func CoinbaseTx

func CoinbaseTx(to []byte, value int) *Transaction

func ContractCreateTx

func ContractCreateTx() *Transaction

func CreateTx

func CreateTx(from, to []byte, value int) *Transaction

func DeserializeTransaction

func DeserializeTransaction(data []byte) Transaction

func (Transaction) Serialize

func (tx Transaction) Serialize() []byte

type TxType

type TxType int8
const (
	TxNormal         TxType = 0
	TxCoinbase       TxType = 1
	TxContractCreate TxType = 2
	TxContractCall   TxType = 3
)

Jump to

Keyboard shortcuts

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