blockchain

package
v0.0.0-...-dc266c9 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Address2PubHash

func Address2PubHash(address []byte) []byte

func PubkeyHash

func PubkeyHash(publicKey []byte) []byte

func RemoveCandidateBlockFile

func RemoveCandidateBlockFile() error

func SimplePaymentValidation

func SimplePaymentValidation(txid, mtroothash []byte, route []int, hashroute [][]byte) bool

func ToHexInt

func ToHexInt(num int64) []byte

Types

type Block

type Block struct {
	Timestamp    int64
	Height       uint32
	Hash         []byte
	Transactions []*Transaction
	PrevHash     []byte
	Nonce        int64
	MTree        *MerkleTree
}

func CreateBlock

func CreateBlock(txs []*Transaction, prevHash []byte, height uint32) *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() *BlockChain

func InitBlockChain

func InitBlockChain(address []byte) *BlockChain

func (*BlockChain) AddBlock

func (chain *BlockChain) AddBlock(transactions []*Transaction, height uint32)

func (*BlockChain) BackOgPrevHash

func (chain *BlockChain) BackOgPrevHash() []byte

func (*BlockChain) FindSpendableOutputs

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

func (*BlockChain) FindTransaction

func (bc *BlockChain) FindTransaction(txID []byte) (Transaction, error)

func (*BlockChain) FindUTXO

func (chain *BlockChain) FindUTXO(address []byte) []UTXO

func (*BlockChain) FindUnspentTransactions

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

func (*BlockChain) GetCurrentBlock

func (chain *BlockChain) GetCurrentBlock() *Block

func (*BlockChain) Iterator

func (chain *BlockChain) Iterator() *BlockChainIterator

func (*BlockChain) RunMine

func (chain *BlockChain) RunMine()

func (*BlockChain) SignTransaction

func (bc *BlockChain) SignTransaction(tx *Transaction, privKey ecdsa.PrivateKey)

func (*BlockChain) VerifyTransaction

func (bc *BlockChain) VerifyTransaction(tx *Transaction) bool

type BlockChainIterator

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

func (*BlockChainIterator) Next

func (iterator *BlockChainIterator) Next() *Block

type CandidateBlock

type CandidateBlock struct {
	PubTx []*Transaction
}

func CreateCandidateBlock

func CreateCandidateBlock() (*CandidateBlock, error)

func (*CandidateBlock) AddTransaction

func (cb *CandidateBlock) AddTransaction(transaction *Transaction)

func (*CandidateBlock) LoadFile

func (cb *CandidateBlock) LoadFile() error

func (*CandidateBlock) SaveFile

func (cb *CandidateBlock) SaveFile()

type MerkleNode

type MerkleNode struct {
	LeftNode  *MerkleNode
	RightNode *MerkleNode
	Data      []byte // Hash
}

func CreateMerkleNode

func CreateMerkleNode(left, right *MerkleNode, data []byte) *MerkleNode

func (*MerkleNode) Find

func (mn *MerkleNode) Find(data []byte, route []int, hashroute [][]byte) (bool, []int, [][]byte)

type MerkleTree

type MerkleTree struct {
	RootNode *MerkleNode
}

func CrateMerkleTree

func CrateMerkleTree(txs []*Transaction) *MerkleTree

func (*MerkleTree) BackValidationRoute

func (mt *MerkleTree) BackValidationRoute(txid []byte) ([]int, [][]byte)

type ProofOfWork

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

func NewProofOfWork

func NewProofOfWork(b *Block) *ProofOfWork

func (*ProofOfWork) InitNonce

func (pow *ProofOfWork) InitNonce(nonce int64) []byte

func (*ProofOfWork) Run

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

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() bool

type Transaction

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

func CoinbaseTx

func CoinbaseTx(toAddress, signature, publickey []byte) *Transaction

func NewTransaction

func NewTransaction(from, to []byte, amount int, chain *BlockChain, privkey ecdsa.PrivateKey) *Transaction

func (*Transaction) IsCoinbase

func (tx *Transaction) IsCoinbase() bool

func (*Transaction) PlainCopy

func (tx *Transaction) PlainCopy() Transaction

func (*Transaction) PlainHash

func (tx *Transaction) PlainHash(inidx int, prevPubKeyHash []byte) []byte

func (*Transaction) SetID

func (tx *Transaction) SetID()

func (*Transaction) Sign

func (tx *Transaction) Sign(privKey ecdsa.PrivateKey, prevTXs map[string]Transaction)

func (*Transaction) TxHash

func (tx *Transaction) TxHash() []byte

func (*Transaction) Verify

func (tx *Transaction) Verify(prevTXs map[string]Transaction) bool

type TxInput

type TxInput struct {
	TxID   []byte
	Out    int
	Sig    []byte
	PubKey []byte
}

func (*TxInput) CanUnlock

func (in *TxInput) CanUnlock(pubHash []byte) bool

type TxOutput

type TxOutput struct {
	Value      int
	HashPubKey []byte
}

func (*TxOutput) CanBeUnlocked

func (out *TxOutput) CanBeUnlocked(pubkeyhash []byte) bool

func (*TxOutput) Lock

func (out *TxOutput) Lock(address []byte)

type UTXO

type UTXO struct {
	TxID   []byte
	OutIdx int
	Value  int
}

func DeserializeUTXO

func DeserializeUTXO(data []byte) *UTXO

func (*UTXO) Serialize

func (u *UTXO) Serialize() []byte

Jump to

Keyboard shortcuts

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