blockchain

package
v0.0.0-...-85f3384 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const Difficulty = 12

Variables

This section is empty.

Functions

func DBexists

func DBexists() bool

func Handler

func Handler(err error)

func ToHex

func ToHex(num int64) []byte

Types

type Block

type Block struct {
	Hash         []byte
	Transactions []*Transaction
	PrevHash     []byte
	Nonce        int
}

func CreateBlock

func CreateBlock(txs []*Transaction, prevHash []byte) *Block

func Deserialize

func Deserialize(data []byte) *Block

func Genesis

func Genesis(coinbase *Transaction) *Block

func (*Block) HashTransactions

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

func (*Block) Serialize

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

type Blockchain

type Blockchain struct {
	LastHash []byte
	Database *badger.DB
}

func ContinueBlockchain

func ContinueBlockchain(address string) *Blockchain

func InitBlockchain

func InitBlockchain(address string) *Blockchain

func (*Blockchain) AddBlock

func (chain *Blockchain) AddBlock(data string)

func (*Blockchain) Iterator

func (chain *Blockchain) Iterator() *BlockchainIterator

type BlockchainIterator

type BlockchainIterator struct {
	Database *badger.DB
	// contains filtered or unexported fields
}

func (*BlockchainIterator) Next

func (iter *BlockchainIterator) Next() *Block

type ProofOfWork

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

func NewProof

func NewProof(b *Block) *ProofOfWork

func (*ProofOfWork) InitData

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

func (*ProofOfWork) Run

func (pow *ProofOfWork) Run() (int, []byte)

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

type Transaction

type Transaction struct {
	ID      []byte
	Inputs  []TxInput
	Outputs []TxOutput
}

func CoinbaseTx

func CoinbaseTx(to, data string) *Transaction

func (*Transaction) IsCoinbase

func (tx *Transaction) IsCoinbase() bool

func (*Transaction) SetID

func (tx *Transaction) SetID()

type TxInput

type TxInput struct {
	ID  []byte
	Out int
	Sig string
}

func (*TxInput) CanUnlock

func (in *TxInput) CanUnlock(data string) bool

type TxOutput

type TxOutput struct {
	Value  int
	PubKey string
}

func (*TxOutput) CanBeUnlocked

func (out *TxOutput) CanBeUnlocked(data string) bool

Jump to

Keyboard shortcuts

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