Documentation ¶
Index ¶
- type Block
- func (b *Block) AddTransaction(tx *Transaction) bool
- func (b *Block) ComputeHash(computeOnly bool) ([]byte, error)
- func (b *Block) ComputeMerkleRoot(computeOnly bool) ([]byte, error)
- func (b *Block) GetInterface(includeTx bool, omitHash bool) interface{}
- func (b *Block) GetSerialized(includeTx bool, omitHash bool) ([]byte, error)
- func (b Block) String() string
- func (b *Block) UpdateHash() error
- func (b *Block) VerifyMerkleTreeTx(tx *Transaction) bool
- type Blockchain
- func (b *Blockchain) AddBlock(block *Block) (bool, error)
- func (b *Blockchain) GetBlock(hash []byte) (*Block, error)
- func (b *Blockchain) GetCurrentBlock() (*Block, error)
- func (b *Blockchain) GetDB() []byte
- func (b *Blockchain) IsChainValid(verbose bool) (bool, error)
- func (b *Blockchain) ValidateBlock(block *Block, prevBlock *Block) (bool, error)
- type Transaction
- type Wallet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct { IDx int64 `json:"i"` MerkleRoot []byte `json:"m"` Timestamp int64 `json:"ts"` Transactions []Transaction `json:"txs"` Hash []byte `json:"h"` PrevHash []byte `json:"ph"` Signature []byte `json:"s"` // contains filtered or unexported fields }
Block represents each individual block in the chain.
func BlockFromBytes ¶
BlockFromBytes converts a block directly from the fs into an unserialized Block object.
func (*Block) AddTransaction ¶
func (b *Block) AddTransaction(tx *Transaction) bool
AddTransaction adds a transaction to the blockchain.
func (*Block) ComputeHash ¶
ComputeHash computes the hash of the block.
func (*Block) ComputeMerkleRoot ¶
ComputeMerkleRoot computes the merkle root based on
func (*Block) GetInterface ¶
GetInterface returns the interface.
func (*Block) GetSerialized ¶
GetSerialized returns the msgpack version of this block.
func (*Block) VerifyMerkleTreeTx ¶
func (b *Block) VerifyMerkleTreeTx(tx *Transaction) bool
VerifyMerkleTreeTx verifies if a transaction is part of the merkle tree.
type Blockchain ¶
type Blockchain struct { Height int64 `json:"h"` ID int64 `json:"id"` CurrentHash []byte `json:"ch"` // contains filtered or unexported fields }
Blockchain represents the object that handles the entire blockchain database.
func CreateChainInstance ¶
func CreateChainInstance(genesisHash []byte, currentHash []byte) (*Blockchain, error)
CreateChainInstance creates a new instance of the blockchain object.
func InitChainDB ¶
func InitChainDB() (*Blockchain, error)
InitChainDB locates and loads the blockchain.
func (*Blockchain) AddBlock ¶
func (b *Blockchain) AddBlock(block *Block) (bool, error)
AddBlock adds a block to the chain.
func (*Blockchain) GetBlock ¶
func (b *Blockchain) GetBlock(hash []byte) (*Block, error)
GetBlock get's a block by its hash.
func (*Blockchain) GetCurrentBlock ¶
func (b *Blockchain) GetCurrentBlock() (*Block, error)
GetCurrentBlock gets the current block.
func (*Blockchain) IsChainValid ¶
func (b *Blockchain) IsChainValid(verbose bool) (bool, error)
IsChainValid checks if the blockchain is consistent and that all blocks are valid. Every block in the chain needs to have the correct index (IDx), hash and previous hash.
func (*Blockchain) ValidateBlock ¶
func (b *Blockchain) ValidateBlock(block *Block, prevBlock *Block) (bool, error)
ValidateBlock validates that a block conforms with the rules of our blockchain. Which means that the prevHash of our new block needs to match the hash of the prevBlock. Also, the hash of the block, as well as the merkle root, need to check out.
type Transaction ¶
type Transaction struct { Hash []byte `json:"h"` Amount uint64 `json:"a"` From []byte `json:"f"` To []byte `json:"t"` Signature []byte `json:"s"` }
Transaction represents a single transaction from and to another wallet in the dimosthenes network.
func (Transaction) CalculateHash ¶
func (tx Transaction) CalculateHash() ([]byte, error)
CalculateHash calculates the hash of this transaction.
func (Transaction) Equals ¶
func (tx Transaction) Equals(otherTx merkletree.Content) (bool, error)
Equals checks two transactions for equality.
func (Transaction) String ¶
func (tx Transaction) String() string
String returns the string representation of the transaction.
type Wallet ¶
Wallet defines the wallet structure.
func (*Wallet) Unserialize ¶
Unserialize imports a wallet file.