Documentation
¶
Index ¶
- func GetSignedData(privKey ecdsa.PrivateKey, dataToSign *TxPreSignature) []byte
- func HashPubKey(pubKey []byte) []byte
- func ValidateAddress(address string) bool
- type Block
- type Blockchain
- type BlockchainIterator
- type CLI
- type ProofOfWork
- type Transaction
- type Tx
- type TxInput
- type TxOutput
- type TxOutputs
- type TxPreSignature
- type UTXOSet
- type Wallet
- type Wallets
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSignedData ¶
func GetSignedData(privKey ecdsa.PrivateKey, dataToSign *TxPreSignature) []byte
func ValidateAddress ¶
ValidateAddress check if address if valid
Types ¶
type Block ¶
type Block struct {
Timestamp int64
Transactions []*Tx
PrevBlockHash []byte
Hash []byte
Nonce int64
Height int
}
func DeserializeBlock ¶
func NewGenesisBlock ¶
func (*Block) HashTransactions ¶
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
func CreateBlockchain ¶
func CreateBlockchain(address, nodeId string) *Blockchain
func NewBlockchain ¶
func NewBlockchain(nodeID string) *Blockchain
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block *Block)
func (*Blockchain) FindTransaction ¶
func (bc *Blockchain) FindTransaction(ID []byte) (Tx, error)
FindTransaction finds a transaction by its ID
func (*Blockchain) FindUTXO ¶
func (bc *Blockchain) FindUTXO() map[string]TxOutputs
FindUTXO finds all unspent transaction outputs and returns transactions with spent outputs removed
func (*Blockchain) Iterator ¶
func (bc *Blockchain) Iterator() *BlockchainIterator
Iterator returns a BlockchainIterat
type BlockchainIterator ¶
type BlockchainIterator struct {
// contains filtered or unexported fields
}
BlockchainIterator is used to iterate over blockchain blocks
func (*BlockchainIterator) Next ¶
func (i *BlockchainIterator) Next() *Block
Next returns next block starting from the tip
type CLI ¶
type CLI struct {
// contains filtered or unexported fields
}
func NewCLI ¶
func NewCLI(bc *Blockchain) *CLI
type ProofOfWork ¶
type ProofOfWork struct {
// contains filtered or unexported fields
}
func NewProofOfWork ¶
func NewProofOfWork(b *Block) *ProofOfWork
func (*ProofOfWork) PrepareData ¶
func (pow *ProofOfWork) PrepareData(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
Input []TxInput
Output []TxOutput
}
func CoinbaseTx ¶
func CoinbaseTx(to string, data string) *Transaction
type Tx ¶
type Tx struct {
Id []byte
Inputs []TxInput
Outputs []TxOutput
}
func DeserializeTx ¶
func NewCoinbaseTx ¶
func NewUTXOTransaction ¶
func (*Tx) IsCoinbase ¶
type TxOutput ¶
func NewTxOutput ¶
func (*TxOutput) AssignPubKeyHash ¶
func (*TxOutput) VerifyTxOutput ¶
type TxPreSignature ¶
func NewPreSignature ¶
func NewPreSignature(currentTx *Tx, prevTxMap map[string]Tx, currentInput *TxInput) TxPreSignature
type UTXOSet ¶
type UTXOSet struct {
Blockchain *Blockchain
}
type Wallet ¶
type Wallet struct {
PrivateKey ecdsa.PrivateKey
PublicKey []byte
}
Wallet stores private and public keys
type Wallets ¶
Wallets stores a collection of wallets
func NewWallets ¶
NewWallets creates Wallets and fills it from a file if it exists
func (*Wallets) CreateWallet ¶
CreateWallet adds a Wallet to Wallets
func (*Wallets) GetAddresses ¶
GetAddresses returns an array of addresses stored in the wallet file
func (*Wallets) LoadFromFile ¶
LoadFromFile loads wallets from the file
func (Wallets) SaveToFile ¶
SaveToFile saves wallets to a file