blockchain

package
v0.0.0-...-94e4465 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const Difficutly = 20

Variables

This section is empty.

Functions

func DBexists

func DBexists() bool

func Handle

func Handle(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(transaction []*Transaction)

func (*BlockChain) FindSpendableOutputs

func (chain *BlockChain) FindSpendableOutputs(address string, amount int) (int, map[string][]int)

func (*BlockChain) FindUTXO

func (chain *BlockChain) FindUTXO(address string) []TxOutput

func (*BlockChain) FindUnspentTransactions

func (chain *BlockChain) FindUnspentTransactions(address string) []Transaction

func (*BlockChain) Iterator

func (chain *BlockChain) Iterator() *BlockChainIterator

type BlockChainIterator

type BlockChainIterator struct {
	CurrentHash []byte
	Database    *badger.DB
}

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 NewTransaction

func NewTransaction(from, to string, amount int, chain *BlockChain) *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