blockchain

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

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

This wallet code is specifically coupled with the node itself

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 PublicKeyHexToAddress

func PublicKeyHexToAddress(pubKeyHex string) (string, error)

PublicKeyHexToAddress convert the base58-encoded public key pubkey to hexadecimal string of public key

func StartNode

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

func TransactionsToString

func TransactionsToString(transactions []Transaction) string

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)

func (*Blockchain) GetLatestBlockHeight

func (bc *Blockchain) GetLatestBlockHeight() int

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 Input

type Input struct {
	PrevTxID    string
	OutputIndex int
	Value       int
}

func GetInputsForTxByAddress

func GetInputsForTxByAddress(address string) []Input

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 NodeIdentifier

type NodeIdentifier struct {
	PeerID string `json:"peer_id"`
	Addr   string `json:"address"`
}

type Output

type Output struct {
	OutputIndex int
	Value       int
	Address     string
}

func GetUTXOsByAddress

func GetUTXOsByAddress(address string) []Output

type SyncRequest

type SyncRequest struct {
	FromHeight int `json:"from_height"`
}

type SyncResponse

type SyncResponse struct {
	Blocks []*Block `json:"blocks"`
}

type Transaction

type Transaction struct {
	TxID       string   `json:"transaction_id"`
	Sender     string   `json:"sender"`
	Recipent   string   `json:"recipent"`
	Amount     int      `json:"amount"`
	Signature  string   `json:"signature"`
	Inputs     []Input  `json:"inputs"`
	Outputs    []Output `json:"outputs"`
	IsCoinbase bool     `json:"is_coinbase"`
}

func GenerateCoinbaseTx

func GenerateCoinbaseTx() Transaction

func GetUserTxHistory

func GetUserTxHistory(walletAddress string) []Transaction

func (*Transaction) Hash

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

func (*Transaction) Sign

func (tx *Transaction) Sign(privateKey *ecdsa.PrivateKey) error

type UTXOSet

type UTXOSet struct {
	UTXOs map[string]map[int]Output // map of transaction id mapped to output indexes mapped to Output
}

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)

type Wallet

type Wallet struct {
	PublicKey string
	Address   string
	// contains filtered or unexported fields
}

func GenerateWallet

func GenerateWallet() *Wallet

Jump to

Keyboard shortcuts

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