Documentation ¶
Index ¶
- func CalculateHash(data string) []byte
- func PrintPublicAddress(k string) (string, error)
- type Block
- type BlockChain
- func (bc *BlockChain) GetAllBalances() string
- func (bc *BlockChain) GetBalance(address []byte) float32
- func (bc BlockChain) GetLatestBlock() Block
- func (bc *BlockChain) MineTransactions(address []byte)
- func (bc *BlockChain) PushTransactions(tx ...Transaction) error
- func (bc BlockChain) String() string
- func (bc BlockChain) Verify() bool
- type Key
- type Transaction
- type TransactionList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateHash ¶
CalculateHash calculates the Hash of a generic string Value
func PrintPublicAddress ¶
PrintPublicAddress prints the public key value from a given key.
Types ¶
type Block ¶
type Block struct { Id uuid.UUID Transactions TransactionList Hash []byte PreviousHash []byte // contains filtered or unexported fields }
Block to be added to an existing BlockChain.
func NewBlock ¶
func NewBlock(t TransactionList) Block
NewBlock instantiates a new Block which can then be added to an existing BlockChain.
func (Block) CheckTransactions ¶
CheckTransactions in the Block. Calls VerifyTransactions underneath.
func (Block) ReCalculateHash ¶
ReCalculateHash is used for under the Verify function. Used for checking stored vs actual hashes.
type BlockChain ¶
type BlockChain struct { Chain []Block Difficulty int32 PendingTransactions TransactionList MiningReward float32 }
BlockChain object to be instantiated and to have Blocks appended to its Genesis Block
func NewBlockChain ¶
func NewBlockChain(d int32, mr float32) *BlockChain
NewBlockChain instantiates a new BlockChain to be used. Can append existing Blocks to it.
func (*BlockChain) GetAllBalances ¶
func (bc *BlockChain) GetAllBalances() string
GetAllBalances in the BlockChain from Genesis.
func (*BlockChain) GetBalance ¶
func (bc *BlockChain) GetBalance(address []byte) float32
GetBalance retrieves the address' current balance from Genesis Block -> last Block
func (BlockChain) GetLatestBlock ¶
func (bc BlockChain) GetLatestBlock() Block
GetLatestBlock returns the final Block in the BlockChain
func (*BlockChain) MineTransactions ¶
func (bc *BlockChain) MineTransactions(address []byte)
MineTransactions mines current pending Transactions on the BlockChain
func (*BlockChain) PushTransactions ¶
func (bc *BlockChain) PushTransactions(tx ...Transaction) error
PushTransactions to the BlockChain, use MineTransactions to process them.
func (BlockChain) String ¶
func (bc BlockChain) String() string
String outputs the BlockChain and its underlying Blocks in JSON string format.
func (BlockChain) Verify ¶
func (bc BlockChain) Verify() bool
Verify is used to verify the integrity of the BlockChain. From the last Block to Genesis, the PreviousHash field should be linked to the proper prior Block's Hash field. Similar to a singly linked list.
type Key ¶
type Key struct { Name string Key *ecdsa.PrivateKey }
Key object to handle BlockChain internals.
type Transaction ¶
Transaction type to be used within a Block inside the BlockChain
func NewTransaction ¶
func NewTransaction(f, t []byte, a float32) Transaction
NewTransaction instantiates a new transaction to be mined in the BlockChain
func ReadTransactionFromJSON ¶
func ReadTransactionFromJSON() (*Transaction, error)
ReadTransactionFromJSON reads a Transaction from the working directory in transaciotn.json and loads it into memory.
func (Transaction) SaveTransactionToJSON ¶
func (t Transaction) SaveTransactionToJSON() error
SaveTransactionToJSON saves a Transaction to the working directory named transaction.json. Only 1 Transaction can be saved.
func (*Transaction) SignTransaction ¶
func (t *Transaction) SignTransaction(k *Key) error
SignTransaction signs a Transaction with a Key
func (Transaction) String ¶
func (t Transaction) String() string
String outputs a Transaction in JSON string format.
func (*Transaction) VerifyTransaction ¶
func (t *Transaction) VerifyTransaction() bool
VerifyTransaction checks the signature, calculated hash and public key to see if they match.
type TransactionList ¶
type TransactionList []Transaction
TransactionList used to process Transactions in a BlockChain
func (TransactionList) String ¶
func (tx TransactionList) String() string
String outputs a TransactionList in JSON string format.