core

package
v0.0.0-...-b00a37c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2021 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

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

func BlockFromBytes(b []byte) (*Block, error)

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

func (b *Block) ComputeHash(computeOnly bool) ([]byte, error)

ComputeHash computes the hash of the block.

func (*Block) ComputeMerkleRoot

func (b *Block) ComputeMerkleRoot(computeOnly bool) ([]byte, error)

ComputeMerkleRoot computes the merkle root based on

func (*Block) GetInterface

func (b *Block) GetInterface(includeTx bool, omitHash bool) interface{}

GetInterface returns the interface.

func (*Block) GetSerialized

func (b *Block) GetSerialized(includeTx bool, omitHash bool) ([]byte, error)

GetSerialized returns the msgpack version of this block.

func (Block) String

func (b Block) String() string

String returns the string representation of the transaction.

func (*Block) UpdateHash

func (b *Block) UpdateHash() error

UpdateHash updates the block's hash

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) GetDB

func (b *Blockchain) GetDB() []byte

GetDB returns the genesis hash.

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

type Wallet struct {
	KeyPair *crypto.KeyPair
}

Wallet defines the wallet structure.

func (*Wallet) Serialize

func (w *Wallet) Serialize() []byte

Serialize serializes the wallet

func (*Wallet) Unserialize

func (w *Wallet) Unserialize(bin []byte) error

Unserialize imports a wallet file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL