haskoin-node-0.9.2: Haskoin Node P2P library for Bitcoin and Bitcoin Cash

CopyrightNo rights reserved
LicenseUNLICENSE
Maintainerxenog@protonmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Haskoin.Node

Description

Integrates peers, manager, and block header synchronization processes.

Messages from peers that aren't consumed by the peer manager or chain are forwarded to the listen action provided in the node configuration.

Synopsis

Documentation

type Host = String Source #

Type alias for a hostname.

type Port = Int Source #

Type alias for a port number.

type HostPort = (Host, Port) Source #

Type alias for a combination of hostname and port.

type Peer = Mailbox PeerMessage Source #

Mailbox for a peer.

type Chain = Mailbox ChainMessage Source #

Mailbox for chain header syncing process.

type Manager = Mailbox ManagerMessage Source #

Mailbox for peer manager process.

data ChainMessage Source #

Messages that can be sent to the chain process.

data ManagerMessage Source #

Messages that can be sent to the peer manager.

data OnlinePeer Source #

Data structure representing an online peer.

Constructors

OnlinePeer 

Fields

data NodeConfig Source #

General node configuration.

Constructors

NodeConfig 

Fields

data NodeEvent Source #

Chain and peer events generated by the node.

Constructors

ChainEvent !ChainEvent

events from the chain syncing process

PeerEvent !PeerEvent

events from peers and peer manager

Instances
Eq NodeEvent Source # 
Instance details

Defined in Network.Haskoin.Node.Common

data ChainEvent Source #

Events originating from chain syncing process.

Constructors

ChainBestBlock !BlockNode

chain has new best block

ChainSynced !BlockNode

chain is in sync with the network

Instances
Eq ChainEvent Source # 
Instance details

Defined in Network.Haskoin.Node.Common

Show ChainEvent Source # 
Instance details

Defined in Network.Haskoin.Node.Common

data PeerEvent Source #

Events originating from peers and the peer manager.

Constructors

PeerConnected !Peer !SockAddr

new peer connected

PeerDisconnected !Peer !SockAddr

peer disconnected

PeerMessage !Peer !Message

peer sent a message

Instances
Eq PeerEvent Source # 
Instance details

Defined in Network.Haskoin.Node.Common

data PeerException Source #

Reasons why a peer may stop working.

Constructors

PeerMisbehaving !String

peer is being a naughty boy

DuplicateVersion

peer sent an extra version message

DecodeHeaderError

incoming message headers could not be decoded

CannotDecodePayload

incoming message payload could not be decoded

PeerIsMyself

nonce for peer matches ours

PayloadTooLarge !Word32

message payload too large

PeerAddressInvalid

peer address not valid

PeerSentBadHeaders

peer sent wrong headers

NotNetworkPeer

peer cannot serve block chain data

PeerNoSegWit

peer has no segwit support

PeerTimeout

request to peer timed out

PurgingPeer

peers are being purged

UnknownPeer

peer is unknown

withNode :: (MonadLoggerIO m, MonadUnliftIO m) => NodeConfig -> ((Manager, Chain) -> m a) -> m a Source #

Launch a node in the background. Pass a Manager and Chain to a function. Node will stop once the function ends.

node :: (MonadLoggerIO m, MonadUnliftIO m) => NodeConfig -> Inbox ManagerMessage -> Inbox ChainMessage -> m () Source #

Launch node process in the foreground.

managerGetPeers :: MonadIO m => Manager -> m [OnlinePeer] Source #

Get list of connected peers from manager.

managerGetPeer :: MonadIO m => Peer -> Manager -> m (Maybe OnlinePeer) Source #

Get information for an online peer from manager.

killPeer :: MonadIO m => PeerException -> Peer -> m () Source #

Kill a peer with the provided exception.

sendMessage :: MonadIO m => Message -> Peer -> m () Source #

Send a network message to peer.

peerGetPublisher :: MonadUnliftIO m => Int -> Peer -> m (Maybe (Publisher Message)) Source #

Get a publisher associated to a peer. Must provide timeout as peer may disconnect and become unresponsive.

peerGetBlocks :: MonadUnliftIO m => Network -> Int -> Peer -> [BlockHash] -> m (Maybe [Block]) Source #

Request full blocks from peer. Will return Nothing if the list of blocks returned by the peer is incomplete, comes out of order, or a timeout is reached.

peerGetTxs :: MonadUnliftIO m => Network -> Int -> Peer -> [TxHash] -> m (Maybe [Tx]) Source #

Request transactions from peer. Will return Nothing if the list of transactions returned by the peer is incomplete, comes out of order, or a timeout is reached.

chainGetBlock :: MonadIO m => BlockHash -> Chain -> m (Maybe BlockNode) Source #

Get a block header from Chain process.

chainGetBest :: MonadIO m => Chain -> m BlockNode Source #

Get best block header from chain process.

chainGetAncestor :: MonadIO m => BlockHeight -> BlockNode -> Chain -> m (Maybe BlockNode) Source #

Get ancestor of BlockNode at BlockHeight from chain process.

chainGetParents :: MonadIO m => BlockHeight -> BlockNode -> Chain -> m [BlockNode] Source #

Get parents of BlockNode starting at BlockHeight from chain process.

chainGetSplitBlock :: MonadIO m => BlockNode -> BlockNode -> Chain -> m BlockNode Source #

Get last common block from chain process.

chainBlockMain :: MonadIO m => BlockHash -> Chain -> m Bool Source #

Is given BlockHash in the main chain?

chainIsSynced :: MonadIO m => Chain -> m Bool Source #

Is chain in sync with network?

myVersion :: Word32 Source #

Our protocol version.