Documentation ¶
Index ¶
- Constants
- func BlockSerialize(block *Block) []byte
- func DBexists() bool
- func DBopen() *badger.DB
- func Handle(err error)
- func Hexify(number int64) []byte
- func TXOListSerialize(txos *TXOList) []byte
- func TxnSerialize(txn *Transaction) []byte
- type Block
- type BlockChain
- func (chain *BlockChain) AccumulateUTX0S() map[string]TXOList
- func (chain *BlockChain) AddBlock(blocktxns []*Transaction) *Block
- func (chain *BlockChain) CollectSpendableTXOS(publickeyhash []byte, amount int) (int, map[string][]int)
- func (chain *BlockChain) CountUTXOS() int
- func (chain *BlockChain) DeleteKeyPrefix(prefix []byte)
- func (chain *BlockChain) FetchUTXOS(publickeyhash []byte) TXOList
- func (chain *BlockChain) FindTransaction(txnid []byte) (Transaction, error)
- func (chain *BlockChain) ReindexUTXOS()
- func (chain *BlockChain) SignTransaction(txn *Transaction, privatekey ecdsa.PrivateKey)
- func (chain *BlockChain) UpdateUTXOS(block *Block)
- func (chain *BlockChain) VerifyTransaction(txn *Transaction, privatekey ecdsa.PrivateKey) bool
- type BlockChainIterator
- type MerkleNode
- type MerkleTree
- type TXOList
- type Transaction
- func (txn *Transaction) GenerateHash() []byte
- func (txn *Transaction) GenerateTrimCopy() Transaction
- func (txn *Transaction) IsCoinbaseTxn() bool
- func (txn *Transaction) Sign(privatekey ecdsa.PrivateKey, prevtxns map[string]Transaction)
- func (txn *Transaction) String() string
- func (txn *Transaction) Verify(prevtxns map[string]Transaction) bool
- type TxInput
- type TxOutput
Constants ¶
const WorkDifficulty = 18
Variables ¶
This section is empty.
Functions ¶
func BlockSerialize ¶
A function to serialize a Block into gob of bytes
func TXOListSerialize ¶
A function to serialize a UTXO into gob of bytes
func TxnSerialize ¶
func TxnSerialize(txn *Transaction) []byte
A function to serialize a Transaction into gob of bytes
Types ¶
type Block ¶
type Block struct { Hash []byte // Represents the hash of the Block PrevHash []byte // Represents the hash of the previous Block Transactions []*Transaction // Represents the transaction on the Block Nonce int // Represents the nonce number that signed the block Difficulty int // Represent the difficulty value to sign the block }
A structure that represents a single Block on the Animus BlockChain
func BlockDeserialize ¶
A function to deserialize a gob of bytes into a Block
func NewBlock ¶
func NewBlock(txs []*Transaction, prevHash []byte) *Block
A constructor function that generates and returns a new block from th hash of the previous block and a block data. Adds the data to a block and signs it using the PoW algorithm.
func (*Block) Compose ¶
A method of Block that composes and returns the block data as slice of bytes for a given nonce number.
Considers the block data, the hash of the previous block, the block work difficulty and the given nonce number.
func (*Block) GenerateProofTarget ¶
A method of Block that generates the max value of the hash to sign the block. Returns a big integer
func (*Block) GenerateTransactionsHash ¶
A method of Block that generates the hash of all transaction on the block
type BlockChain ¶
type BlockChain struct { Database *badger.DB // Represents the reference to the chain database LastHash []byte // Represents the hash of the last block on the chain }
A structure that represents the Animus BlockChain
func AnimateBlockChain ¶
func AnimateBlockChain() (*BlockChain, error)
A constructor function that animates an existing blockchain i.e brings it to life. Returns an error if no Animus Blockchain exists.
func SeedBlockChain ¶
func SeedBlockChain(address string) (*BlockChain, error)
A constructor function that seeds a new blockchain i.e creates one. Returns an error if an Animus Blockchain already exists.
func (*BlockChain) AccumulateUTX0S ¶
func (chain *BlockChain) AccumulateUTX0S() map[string]TXOList
A method of BlockChain that accumulates all unspent transactions on the chain and returns them as a map transaction ID to TXOList.
func (*BlockChain) AddBlock ¶
func (chain *BlockChain) AddBlock(blocktxns []*Transaction) *Block
A method of BlockChain that adds a new Block to the chain and returns it
func (*BlockChain) CollectSpendableTXOS ¶
func (chain *BlockChain) CollectSpendableTXOS(publickeyhash []byte, amount int) (int, map[string][]int)
A method of BlockChain that collects the spendable transaction outputs given a public key hash and a target amount upto which to collect.
func (*BlockChain) CountUTXOS ¶
func (chain *BlockChain) CountUTXOS() int
A method of BlockChain that counts the number of unspent transactions stored on the database
func (*BlockChain) DeleteKeyPrefix ¶
func (chain *BlockChain) DeleteKeyPrefix(prefix []byte)
A method of BlockChain that deletes all entries with a given prefix from the Badger DB.
func (*BlockChain) FetchUTXOS ¶
func (chain *BlockChain) FetchUTXOS(publickeyhash []byte) TXOList
A method of BlockChain that fetches the unspent transaction outputs for a given public key hash and returns it in a list of transaction outputs
func (*BlockChain) FindTransaction ¶
func (chain *BlockChain) FindTransaction(txnid []byte) (Transaction, error)
A method of BlockChain that finds a transaction from the chain given a valid Transaction ID
func (*BlockChain) ReindexUTXOS ¶
func (chain *BlockChain) ReindexUTXOS()
A method of BlockChain that reindexes all the utxo layer keys on the database.
func (*BlockChain) SignTransaction ¶
func (chain *BlockChain) SignTransaction(txn *Transaction, privatekey ecdsa.PrivateKey)
A method of BlockChain that signs a transaction given a private key
func (*BlockChain) UpdateUTXOS ¶
func (chain *BlockChain) UpdateUTXOS(block *Block)
A method of BlockChain that updates the utxo layer keys from the transaction of a Block, given the block.
func (*BlockChain) VerifyTransaction ¶
func (chain *BlockChain) VerifyTransaction(txn *Transaction, privatekey ecdsa.PrivateKey) bool
A method of BlockChain that verifies the signature of a transaction given a private key
type BlockChainIterator ¶
type BlockChainIterator struct { CursorHash []byte // Represents the hash of the block that the iterator is currently on Database *badger.DB // Represents the reference to the chain database }
A structure that represents an Iterator for the Animus BlockChain
func NewIterator ¶
func NewIterator(chain *BlockChain) *BlockChainIterator
A constructor function that generates an iterator for the BlockChain
func (*BlockChainIterator) Next ¶
func (iter *BlockChainIterator) Next() *Block
A method of BlockChainIterator that iterates over chain and returns the next block on the chain (backwards) from the chain DB and returns it
type MerkleNode ¶
type MerkleNode struct { Left *MerkleNode Right *MerkleNode Data []byte }
func NewMerkleNode ¶
func NewMerkleNode(left, right *MerkleNode, data []byte) *MerkleNode
type MerkleTree ¶
type MerkleTree struct {
RootNode *MerkleNode
}
func NewMerkleTree ¶
func NewMerkleTree(merkledata [][]byte) *MerkleTree
type TXOList ¶
type TXOList []TxOutput
func TXOListDeserialize ¶
A function to deserialize a gob of bytes into a UTXO
type Transaction ¶
type Transaction struct { ID []byte // Represents the hash of the transaction Inputs []TxInput // Represents the inputs of the transaction Outputs []TxOutput // Represents the outputs of the transaction }
A structure that represents a transaction on the Animus Blockchain
func NewCoinbaseTransaction ¶
func NewCoinbaseTransaction(to string) *Transaction
A constructor function that generates and returns a coinbase Transaction. A Coinbase transaction refers to a first transaction on a block and does not refer to any previous output transactions and contains a token reward for the user who signs the block.
func NewTransaction ¶
func NewTransaction(from, to string, amount int, chain *BlockChain) *Transaction
A constructor function that generates and returns a Transaction given the to and from addresses and the amount to transact.
func TxnDeserialize ¶
func TxnDeserialize(gobdata []byte) *Transaction
A function to deserialize a gob of bytes into a Transaction
func (*Transaction) GenerateHash ¶
func (txn *Transaction) GenerateHash() []byte
A method of Transaction that generates a hash of the Transaction
func (*Transaction) GenerateTrimCopy ¶
func (txn *Transaction) GenerateTrimCopy() Transaction
A method of Transaction that generates a trimmed version of the Transaction that does not include the signature and public keys of the transaction inputs
func (*Transaction) IsCoinbaseTxn ¶
func (txn *Transaction) IsCoinbaseTxn() bool
A method of Transaction that checks if it is a Coinbase Transaction
func (*Transaction) Sign ¶
func (txn *Transaction) Sign(privatekey ecdsa.PrivateKey, prevtxns map[string]Transaction)
A method of Transaction that signs the transaction given the private key of the wallet and a map of previous Transaction IDs to their Transactions.
func (*Transaction) String ¶
func (txn *Transaction) String() string
A method of Transaction that generates a string representation of the transaction and all its inputs and outputs.
func (*Transaction) Verify ¶
func (txn *Transaction) Verify(prevtxns map[string]Transaction) bool
A method of Transaction that verifies if the transaction signature is valid for the given of map Transaction IDs to their Transactions.
type TxInput ¶
type TxInput struct { ID []byte // Represents the reference transaction of which the output is a part OutIndex int // Represents the index of output in the reference transaction Signature []byte // Represents the signature of the transaction PublicKey []byte // Represents the public key of the sending address }
A structure that represents the inputs in a transaction which are really just references to previous outputs
type TxOutput ¶
type TxOutput struct { Value int // Represents the token value of a given transaction output PublicKeyHash []byte // Represents the hash of the public key of the recieving address }
A structure that represents the outputs in a transaction