node

package
v0.0.0-...-63dd8f1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockHeaderList

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

func NewBlockHeaderList

func NewBlockHeaderList() *BlockHeaderList

func (*BlockHeaderList) Add

func (hs *BlockHeaderList) Add(h *genproto.BlockHeader)

func (*BlockHeaderList) Get

func (hs *BlockHeaderList) Get(height int) *genproto.BlockHeader

func (*BlockHeaderList) Height

func (hs *BlockHeaderList) Height() int

type BlockStore

type BlockStore interface {
	Put(*genproto.Block) error
	Get(hash string) (*genproto.Block, error)
}

type Chain

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

func NewChain

func NewChain(bs BlockStore, txs TxStore, utxos UTXOStore) *Chain

func (*Chain) AddBlock

func (c *Chain) AddBlock(block *genproto.Block) error

func (*Chain) GetBlockByHash

func (c *Chain) GetBlockByHash(hash []byte) (*genproto.Block, error)

func (*Chain) GetBlockByHeight

func (c *Chain) GetBlockByHeight(height int) (*genproto.Block, error)

func (*Chain) Height

func (c *Chain) Height() int

func (*Chain) ValidateBlock

func (c *Chain) ValidateBlock(block *genproto.Block) error

func (*Chain) ValidateTransaction

func (c *Chain) ValidateTransaction(tx *genproto.Transaction) error

type ConnectedPeer

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

type MemoryBlockStore

type MemoryBlockStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMemoryBlockStore

func NewMemoryBlockStore() *MemoryBlockStore

func (*MemoryBlockStore) Get

func (s *MemoryBlockStore) Get(hash string) (*genproto.Block, error)

func (*MemoryBlockStore) Put

func (s *MemoryBlockStore) Put(block *genproto.Block) error

type MemoryTxStore

type MemoryTxStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMemoryTxStore

func NewMemoryTxStore() *MemoryTxStore

func (*MemoryTxStore) Get

func (s *MemoryTxStore) Get(hash string) (*genproto.Transaction, error)

func (*MemoryTxStore) Put

type MemoryUTXOStore

type MemoryUTXOStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMemoryUTXOStore

func NewMemoryUTXOStore() *MemoryUTXOStore

func (*MemoryUTXOStore) Get

func (s *MemoryUTXOStore) Get(hash string) (*UTXO, error)

func (*MemoryUTXOStore) Put

func (s *MemoryUTXOStore) Put(utxo *UTXO) error

type Mempool

type Mempool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMempool

func NewMempool() *Mempool

func (*Mempool) Add

func (p *Mempool) Add(tx *genproto.Transaction) bool

func (*Mempool) Clear

func (p *Mempool) Clear() []*genproto.Transaction

func (*Mempool) ClearProcessed

func (p *Mempool) ClearProcessed(threshold time.Duration) []string

func (*Mempool) Has

func (p *Mempool) Has(tx *genproto.Transaction) bool

Has checks if the PROCESSED given transaction is present in the mempool. It returns true if the transaction is present, false otherwise.

func (*Mempool) Size

func (p *Mempool) Size() int

type Node

type Node struct {
	genproto.UnimplementedNodeServer

	NodeConfig
	// contains filtered or unexported fields
}

func NewNode

func NewNode(config NodeConfig, chain *Chain) *Node

func (*Node) HandleTransaction

func (n *Node) HandleTransaction(ctx context.Context, tx *genproto.Transaction) (*emptypb.Empty, error)

func (*Node) Handshake

func (n *Node) Handshake(ctx context.Context, peerNodeInfo *genproto.NodeInfo) (*genproto.NodeInfo, error)

Handshake is called when a new peer node connects to the current node. It exchanges node information with the peer node and adds the peer to the list of connected peers.

If there is an error creating the client connection to the peer node, the function will return an error.

func (*Node) Start

func (n *Node) Start(bootstrapNodes []string) error

Start runs the node server, listening on the configured listen address and registering the node gRPC service. It bootstraps the node by connecting to the specified list of bootstrap nodes.

type NodeConfig

type NodeConfig struct {
	Version    string
	ListenAddr string
	PrivateKey *cryptography.PrivateKey
}

type TxStore

type TxStore interface {
	Get(hash string) (*genproto.Transaction, error)
	Put(*genproto.Transaction) error
}

type UTXO

type UTXO struct {
	Hash string
	// OutIndex is an index of the output in the transaction
	OutIndex int
	Amount   int64
	// Every UTXO is considered “unspent” until it is used as an input in a new transaction.
	// Once it is used, it is no longer a valid UTXO. The blockchain tracks all UTXOs to know what funds are available to be spent.
	IsSpent bool
}

func NewUTXO

func NewUTXO(hash string, outIndex int, amount int64) *UTXO

type UTXOStore

type UTXOStore interface {
	Get(hash string) (*UTXO, error)
	Put(utxo *UTXO) error
}

Jump to

Keyboard shortcuts

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