blockchain

package
v0.0.0-...-4c1c0a6 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 13 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:"idx"`
	Timestamp int64         `json:"timestamp"`
	Txs       []Transaction `json:"txs"`
	PrevHash  []byte        `json:"prevHash"`
	Nonce     int64         `json:"nonce"`
}

func (*Block) HasTx

func (b *Block) HasTx(tx Transaction) bool

type Blockchain

type Blockchain struct {
	Blocks []Block       `json:"block"`
	TxPool []Transaction `json:"txPool"`
}

func NewBlockchain

func NewBlockchain() *Blockchain

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(block Block) error

func (*Blockchain) AddTx

func (bc *Blockchain) AddTx(tx Transaction) (Transaction, error)

func (*Blockchain) CreateGenesisBlock

func (bc *Blockchain) CreateGenesisBlock()

func (*Blockchain) NewBlock

func (bc *Blockchain) NewBlock() (Block, error)

func (*Blockchain) RemoveTx

func (bc *Blockchain) RemoveTx(tx Transaction)

func (*Blockchain) RemoveTxs

func (bc *Blockchain) RemoveTxs(txs []Transaction)

type Node

type Node struct {
	Host string `json:"host"`
}

func (Node) GetPort

func (n Node) GetPort() string

type Transaction

type Transaction struct {
	Id        string          `json:"id"`
	Timestamp int64           `json:"timestamp"`
	Body      TransactionBody `json:"body"`
	Signature string          `json:"signature"`
}

func NewTransaction

func NewTransaction(senderWallet wallet.Wallet, recipientWallet wallet.Wallet, amount float64) (Transaction, error)

func (Transaction) GetBodyHash

func (tx Transaction) GetBodyHash() ([]byte, error)

func (Transaction) IsCoinbase

func (tx Transaction) IsCoinbase() bool

type TransactionBody

type TransactionBody struct {
	Sender    string  `json:"sender"`
	Recipient string  `json:"recipient"`
	Amount    float64 `json:"amount"`
}

Jump to

Keyboard shortcuts

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