network

package
v0.0.0-...-aaa359e Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

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

Api runs the HTTP API for interacting with the node

func NewApi

func NewApi(events chan<- interface{}) *Api

NewApi returns a new instance of the API server

func (*Api) Serve

func (a *Api) Serve() error

Serve starts the API

type BlockCache

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

BlockCache is a synchronized cache for blocks

func (*BlockCache) AddBlock

func (b *BlockCache) AddBlock(block blockchain.Block)

AddBlock adds a block to the cache

func (*BlockCache) ReadBlocks

func (b *BlockCache) ReadBlocks() <-chan blockchain.Block

ReadBlocks returns a channel for iterating over all the blocks in the cache

func (*BlockCache) ReadLastBlock

func (b *BlockCache) ReadLastBlock() blockchain.Block

ReadBlock returns a block from the cache

type NewBlock

type NewBlock struct {
	Block blockchain.Block `json:"block"`
}

NewBlockEvent indicates a peer has mined a new block

type NewPeer

type NewPeer struct {
	Address string `json:"peerAddress"`
}

NewPeer indicates a new peer has been discovered

type NewTransaction

type NewTransaction struct {
	Transaction blockchain.Transaction `json:"transaction"`
}

NewTransaction indicates a peer has received a new transaction

type Node

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

Node represents the node running the blockchain

func NewNode

func NewNode(keyPair *keys.KeyPair) *Node

NewNode returns a new node which mines blocks using the given key pair

func (*Node) Start

func (n *Node) Start()

Start starts the node

type NodeClient

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

NodeClient is an HTTP client used to communicate with a node

func (*NodeClient) GetBlocks

func (c *NodeClient) GetBlocks() ([]blockchain.Block, error)

GetBlocks requests all known blocks from peer node

func (*NodeClient) Greet

func (c *NodeClient) Greet() error

Greet sends a greeting to peer node

func (*NodeClient) SendBlock

func (c *NodeClient) SendBlock(block blockchain.Block) error

SendBlock sends block to peer node

type Peers

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

Peers contains all the peers a node knows about

func (*Peers) Add

func (p *Peers) Add(address string)

Add adds a new peer node and shakes hands with it

func (*Peers) BroadcastBlock

func (p *Peers) BroadcastBlock(block blockchain.Block)

BroadcastBlock sends block to all known peer ndoes

func (*Peers) GetBlocks

func (p *Peers) GetBlocks(address string) ([]blockchain.Block, error)

GetBlocks gets all blocks from peer node

Jump to

Keyboard shortcuts

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