blockchain

package
v0.0.0-...-363fbf2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddressChecksumLength = 4
)

Variables

This section is empty.

Functions

func HashPublicKey

func HashPublicKey(publicKey []byte) []byte

func NewProofOfWork

func NewProofOfWork(block *Block) *proofOfWork

Types

type Block

type Block struct {
	Timestamp    int64
	Transactions []*Transaction
	PreviousHash []byte
	Hash         []byte
	Nonce        int
	Height       int
}

func DeserializeBlock

func DeserializeBlock(data []byte) *Block

func NewBlock

func NewBlock(transactions []*Transaction, previousHash []byte, height int) *Block

TODO: data [string] might not be applicable

func NewGenesisBlock

func NewGenesisBlock(coinbase *Transaction) *Block

func (*Block) HashTransactions

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

func (*Block) Serialize

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

TODO: Maybe use protocol buffers

func (*Block) SetHash

func (block *Block) SetHash()

type Blockchain

type Blockchain struct {
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(nodeID string) *Blockchain

func (*Blockchain) AddBlock

func (blockchain *Blockchain) AddBlock(block *Block)

func (*Blockchain) CloseDB

func (blockchain *Blockchain) CloseDB()

func (*Blockchain) FindTransaction

func (blockchain *Blockchain) FindTransaction(ID []byte) (Transaction, error)

func (*Blockchain) FindUnspentTransactionOutputs

func (blockchain *Blockchain) FindUnspentTransactionOutputs() map[string]TransactionOutputSet

func (*Blockchain) GetBestHeight

func (blockchain *Blockchain) GetBestHeight() int

func (*Blockchain) GetBlock

func (blockchain *Blockchain) GetBlock(blockHash []byte) (Block, error)

func (*Blockchain) GetBlockHashes

func (blockchain *Blockchain) GetBlockHashes() [][]byte

func (*Blockchain) Iterator

func (blockchain *Blockchain) Iterator() *BlockchainIterator

func (*Blockchain) MineBlock

func (blockchain *Blockchain) MineBlock(transactions []*Transaction) *Block

func (*Blockchain) SignTransaction

func (blockchain *Blockchain) SignTransaction(transaction *Transaction, privateKey ecdsa.PrivateKey)

func (*Blockchain) VerifyTransaction

func (blockchain *Blockchain) VerifyTransaction(transaction *Transaction) bool

type BlockchainIterator

type BlockchainIterator struct {
	// contains filtered or unexported fields
}

func (*BlockchainIterator) Next

func (blockchainIterator *BlockchainIterator) Next() *Block

type Transaction

type Transaction struct {
	ID                 []byte
	TransactionInputs  []TransactionInput
	TransactionOutputs []TransactionOutput
}

func DeserializeTransaction

func DeserializeTransaction(data []byte) *Transaction

TODO: Use proto buffers

func NewCoinbaseTransaction

func NewCoinbaseTransaction() *Transaction

func NewTransaction

func NewTransaction(wallet *Wallet, to []byte, amount int, unspentTransactionOutputSet UnspentTransactionOutputSet) *Transaction

func (Transaction) IsCoinbase

func (transaction Transaction) IsCoinbase() bool

func (*Transaction) Serialize

func (transaction *Transaction) Serialize() []byte

TODO: Use proto buffers

func (*Transaction) Sign

func (transaction *Transaction) Sign(privateKey ecdsa.PrivateKey, previousTransactions map[string]Transaction)

func (*Transaction) TrimmedCopy

func (transaction *Transaction) TrimmedCopy() Transaction

func (*Transaction) Verify

func (transaction *Transaction) Verify(previousTransactions map[string]Transaction) bool

type TransactionInput

type TransactionInput struct {
	TransactionID []byte

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

func (*TransactionInput) UsesKey

func (transactionInput *TransactionInput) UsesKey(pubKeyHash []byte) bool

type TransactionOutput

type TransactionOutput struct {
	Value         int
	PublicKeyHash []byte
}

func NewTransactionOutput

func NewTransactionOutput(value int, address []byte) *TransactionOutput

func (*TransactionOutput) IsLockedWithKey

func (transactionOutput *TransactionOutput) IsLockedWithKey(pubKeyHash []byte) bool

func (*TransactionOutput) Lock

func (transactionOutput *TransactionOutput) Lock(address []byte)

type TransactionOutputSet

type TransactionOutputSet struct {
	TransactionOutputs []TransactionOutput
}

func NewTransactionOutputSet

func NewTransactionOutputSet(data []byte) TransactionOutputSet

func (TransactionOutputSet) Serialize

func (transactionOutputSet TransactionOutputSet) Serialize() []byte

TODO: Maybe use proto buffs

type UnspentTransactionOutputSet

type UnspentTransactionOutputSet struct {
	Blockchain *Blockchain
}

func (UnspentTransactionOutputSet) CountTransactions

func (unspentTransactionOutputSet UnspentTransactionOutputSet) CountTransactions() int

func (UnspentTransactionOutputSet) FindSpendableOutputs

func (unspentTransactionOutputSet UnspentTransactionOutputSet) FindSpendableOutputs(publicKeyHash []byte, amount int) (int, map[string][]int)

func (UnspentTransactionOutputSet) FindUnspentTransactionOutputs

func (unspentTransactionOutputSet UnspentTransactionOutputSet) FindUnspentTransactionOutputs(publicKeyHash []byte) []TransactionOutput

func (UnspentTransactionOutputSet) Reindex

func (unspentTransactionOutputSet UnspentTransactionOutputSet) Reindex()

TODO: Using this method should be avoided where possible

func (UnspentTransactionOutputSet) Update

func (unspentTransactionOutputSet UnspentTransactionOutputSet) Update(block *Block)

type Wallet

type Wallet struct {
	PrivateKey ecdsa.PrivateKey
	PublicKey  []byte
}

func NewWallet

func NewWallet() *Wallet

func (Wallet) GetAddress

func (wallet Wallet) GetAddress() []byte

type Wallets

type Wallets struct {
	Wallets map[string]*Wallet
}

func NewWallets

func NewWallets(nodeID string) (*Wallets, error)

func (*Wallets) CreateWallet

func (wallets *Wallets) CreateWallet() string

func (*Wallets) GetAddresses

func (wallets *Wallets) GetAddresses() []string

func (Wallets) GetWallet

func (wallets Wallets) GetWallet(address string) Wallet

func (Wallets) SaveToFile

func (wallets Wallets) SaveToFile(nodeID string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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