Documentation ¶
Index ¶
- Constants
- func Checksum(payload []byte) []byte
- func DBExists(dbPath string) bool
- func NewKeyPair() (ecdsa.PrivateKey, []byte)
- func PublicKeyHash(pubKey []byte) []byte
- func ValidateAddress(address string) bool
- type Block
- type BlockChain
- func (chain *BlockChain) AddBlock(transactions []*Transaction)
- func (chain *BlockChain) FindSpendableOutputs(address string, amount int) (int, map[string][]int)
- func (chain *BlockChain) FindUTXO(address string) []TXOutput
- func (chain *BlockChain) FindUnspentTransactions(address string) []Transaction
- func (chain *BlockChain) Iterator() *BlockChainIterator
- type BlockChainIterator
- type ProofOfWork
- type TXInput
- type TXOutput
- type Transaction
- type Wallet
- type Wallets
Constants ¶
const Difficulty = 12
Difficulty of mining a new block
Variables ¶
This section is empty.
Functions ¶
func NewKeyPair ¶ added in v1.2.2
func NewKeyPair() (ecdsa.PrivateKey, []byte)
NewKeyPair generates a public and private key pair
func PublicKeyHash ¶ added in v1.2.2
PublicKeyHash generates a public key hash
func ValidateAddress ¶ added in v1.2.2
ValidateAddress checks if the address is valid
Types ¶
type Block ¶
type Block struct { Hash []byte Transactions []*Transaction PrevHash []byte Nonce int }
func CreateBlock ¶
func CreateBlock(txs []*Transaction, prevHash []byte) *Block
CreateBlock creates a new block using the data and the previous block's hash
func (*Block) HashTransactions ¶ added in v1.2.1
HashTransactions returns a hash of the transactions in the block
type BlockChain ¶
BlockChain structure
func ContinueBlockChain ¶ added in v1.2.1
func ContinueBlockChain(dbPath string) *BlockChain
Continue a blockchain by pulling the last hash
func InitBlockChain ¶
func InitBlockChain(dbPath string, address string) *BlockChain
InitBlockChain creates a new blockchain with a genesis block
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(transactions []*Transaction)
AddBlock is a helper function that adds a new block to the chain using the previous block's hash
func (*BlockChain) FindSpendableOutputs ¶ added in v1.2.1
Find transaction outputs for a given address that can be used as inputs for a new transaction
func (*BlockChain) FindUTXO ¶ added in v1.2.1
func (chain *BlockChain) FindUTXO(address string) []TXOutput
Find all unspent transaction outputs for a given address
func (*BlockChain) FindUnspentTransactions ¶ added in v1.2.1
func (chain *BlockChain) FindUnspentTransactions(address string) []Transaction
Find all transactions for a given address that is unspent
func (*BlockChain) Iterator ¶
func (chain *BlockChain) Iterator() *BlockChainIterator
Iterator returns a BlockChainIterator that can be used to iterate over the blockchain.
type BlockChainIterator ¶
An iterator for iterating the blockchain in database
func (*BlockChainIterator) Next ¶
func (iter *BlockChainIterator) Next() *Block
Next returns the next block in the blockchain
type ProofOfWork ¶
Proof of Work structure
func (*ProofOfWork) InitData ¶
func (pow *ProofOfWork) InitData(nonce int) []byte
Prepare data to run the proof of work algorithm
func (*ProofOfWork) Run ¶
func (pow *ProofOfWork) Run() (int, []byte)
Run the proof of work algorithm to find a number that satisfies the target
func (*ProofOfWork) Validate ¶
func (pow *ProofOfWork) Validate() bool
Validate the nonce and the hash of the block
type TXOutput ¶ added in v1.2.1
A transaction output
func (*TXOutput) CanBeUnlocked ¶ added in v1.2.1
Check if the transaction output can be unlocked with the given data
type Transaction ¶ added in v1.2.1
A blockchain transaction
func CoinbaseTx ¶ added in v1.2.1
func CoinbaseTx(to, data string) *Transaction
Make a transaction to the given address
func NewTransaction ¶ added in v1.2.1
func NewTransaction(from string, to string, amount int, chain *BlockChain) (*Transaction, error)
func (*Transaction) IsCoinbase ¶ added in v1.2.1
func (tx *Transaction) IsCoinbase() bool
Check if the transaction is a Coinbase transaction
func (*Transaction) SetID ¶ added in v1.2.1
func (tx *Transaction) SetID()
Set the ID of the transaction
type Wallet ¶ added in v1.2.2
type Wallet struct { PrivateKey ecdsa.PrivateKey PublicKey []byte }
Wallet represents a wallet in the blockchain
type Wallets ¶ added in v1.2.2
Wallets represents a collection of wallets
func CreateWallets ¶ added in v1.2.2
Create wallets
func (*Wallets) GetAllAddresses ¶ added in v1.2.2
Get all wallet addresses
func (*Wallets) LoadFromFile ¶ added in v1.2.2
Load the wallets from a file