blockchain

package
v0.0.0-...-7cb4d51 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset  = "\033[0m"
	Red    = "\033[31m"
	Green  = "\033[32m"
	Yellow = "\033[33m"
	Blue   = "\033[34m"
)

Variables

This section is empty.

Functions

func GeneratePrivKeyForNode

func GeneratePrivKeyForNode(randseed int64) (crypto.PrivKey, error)

func MineBlocks

func MineBlocks(bReceiver <-chan *Block, publisherTopic *pubsub.Topic)

func PublickKeyToAddress

func PublickKeyToAddress(pubKey string) (string, error)

PublickKeyToAddress convert the base58-encoded public key pubkey to address

func StartNode

func StartNode(port int, secio bool, randseed int64, connectAddr string) error

Types

type Block

type Block struct {
	Height     int         `json:"height"`
	TxData     Transaction `json:"transaction_data"`
	Timestamps string      `json:"timestamps"`
	Nonce      int         `json:"nonce"`
	Hash       string      `json:"hash"`
	PrevHash   string      `json:"prev_hash"`
}

func NewBlock

func NewBlock(tx Transaction) *Block

type Blockchain

type Blockchain struct {
	Chain      []*Block
	Difficulty int
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain() *Blockchain

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(b *Block)

type ColorLogger

type ColorLogger struct {
	// contains filtered or unexported fields
}

func NewColorLogger

func NewColorLogger() *ColorLogger

func (*ColorLogger) Error

func (c *ColorLogger) Error(v ...interface{})

func (*ColorLogger) Errorf

func (c *ColorLogger) Errorf(format string, v ...interface{})

func (*ColorLogger) Info

func (c *ColorLogger) Info(v ...interface{})

func (*ColorLogger) Infof

func (c *ColorLogger) Infof(format string, v ...interface{})

func (*ColorLogger) Success

func (c *ColorLogger) Success(v ...interface{})

func (*ColorLogger) Successf

func (c *ColorLogger) Successf(format string, v ...interface{})

func (*ColorLogger) Warn

func (c *ColorLogger) Warn(v ...interface{})

func (*ColorLogger) Warnf

func (c *ColorLogger) Warnf(format string, v ...interface{})

type Mempool

type Mempool struct {
	// contains filtered or unexported fields
}

func NewMempool

func NewMempool() *Mempool

func (*Mempool) AddTransaction

func (m *Mempool) AddTransaction(tx *Transaction)

func (*Mempool) RemoveTransaction

func (m *Mempool) RemoveTransaction(txID string)

type MyNotifiee

type MyNotifiee struct{}

func (*MyNotifiee) Connected

func (n *MyNotifiee) Connected(net network.Network, conn network.Conn)

func (*MyNotifiee) Disconnected

func (n *MyNotifiee) Disconnected(net network.Network, conn network.Conn)

func (*MyNotifiee) Listen

func (n *MyNotifiee) Listen(net network.Network, addr ma.Multiaddr)

func (*MyNotifiee) ListenClose

func (n *MyNotifiee) ListenClose(net network.Network, addr ma.Multiaddr)

type Transaction

type Transaction struct {
	TxID      string `json:"trasaction_id"`
	Sender    string `json:"sender"`
	Recipent  string `json:"recipent"`
	Amount    int    `json:"amount"`
	Signature string `json:"signature"`
	Inputs    []UTXO `json:"inputs"`
	Outputs   []UTXO `json:"outputs"`
}

func (*Transaction) Hash

func (tx *Transaction) Hash() []byte

func (Transaction) String

func (tx Transaction) String() string

type UTXO

type UTXO struct {
	TxID        string
	OutputIndex int
	Amount      int
	Address     string
}

type UTXOSet

type UTXOSet struct {
	UTXOs map[string]map[int]UTXO
}

func (*UTXOSet) AddUTXO

func (us *UTXOSet) AddUTXO(txID string, outputIndex int, amount int, address string)

func (*UTXOSet) GetTotalUTXOsByAddress

func (us *UTXOSet) GetTotalUTXOsByAddress(address string) int

func (*UTXOSet) Remove

func (us *UTXOSet) Remove(txID string, outputIndex int, address string)

Jump to

Keyboard shortcuts

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