<commit_before>{-# LANGUAGE DeriveGeneric   #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies    #-}

-- | Types used for communication about Blocks.

module Pos.Communication.Types.Block
       ( SendBlock (..)
       , SendBlockHeader (..)
       , RequestBlock (..)
       ) where

import           Data.Binary          (Binary)
import           Universum

import           Control.TimeWarp.Rpc (Message (..), messageName')
import           Pos.Ssc.Class.Types  (Ssc)
import           Pos.Types            (Block, HeaderHash, MainBlockHeader)

-- | Message: some node has sent a Block.
data SendBlock ssc =
    SendBlock !(Block ssc)
    deriving (Generic)

-- | Message: some node has sent a BlockHeader.
data SendBlockHeader ssc =
    SendBlockHeader !(MainBlockHeader ssc)
    deriving (Generic)

-- | Message: some node has requested a Block with given HeaderHash.
data RequestBlock ssc =
    RequestBlock !(HeaderHash ssc)
    deriving (Generic)

instance Ssc ssc => Binary (SendBlock ssc)
instance Ssc ssc => Binary (SendBlockHeader ssc)
instance Binary (RequestBlock ssc)

instance (Ssc ssc) => Message (SendBlock ssc) where
    messageName _ = "SendBlock"
    formatMessage = messageName'

instance (Ssc ssc) => Message (SendBlockHeader ssc) where
    messageName _ = "SendBlockHeader"
    formatMessage = messageName'

instance Typeable ssc => Message (RequestBlock ssc) where
    messageName _ = "RequestBlock"
    formatMessage = messageName'<commit_msg>[CSL-255] Message types for blockchain parts<commit_after>{-# LANGUAGE DeriveGeneric   #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies    #-}

-- | Types used for communication about Blocks.

module Pos.Communication.Types.Block
       ( SendBlock (..)
       , SendBlockHeader (..)
       , SendBlockchainPart (..)
       , RequestBlock (..)
       , RequestBlockchainPart (..)
       ) where

import           Data.Binary          (Binary)
import           Universum

import           Control.TimeWarp.Rpc (Message (..), messageName')
import           Pos.Ssc.Class.Types  (Ssc)
import           Pos.Types            (Block, HeaderHash, MainBlockHeader)

-- | Message: some node has sent a Block.
data SendBlock ssc =
    SendBlock !(Block ssc)
    deriving (Generic)

-- | Message: some node has sent a BlockHeader.
data SendBlockHeader ssc =
    SendBlockHeader !(MainBlockHeader ssc)
    deriving (Generic)

-- | Message: some node has sent a part of blockchain
data SendBlockchainPart ssc =
    SendBlockchainPart ![Block ssc]
    deriving (Generic)

-- | Message: some node has requested a Block with given HeaderHash.
data RequestBlock ssc =
    RequestBlock !(HeaderHash ssc)
    deriving (Generic)

-- | Message: some node has requested a part of blockchain
data RequestBlockchainPart ssc = RequestBlockchainPart
    { rbFromBlock  :: !(Maybe (HeaderHash ssc))
    , rbUntilBlock :: !(Maybe (HeaderHash ssc))
    , rbCount      :: !(Maybe Word)
    } deriving (Generic)

instance Ssc ssc => Binary (SendBlock ssc)
instance Ssc ssc => Binary (SendBlockHeader ssc)
instance Ssc ssc => Binary (SendBlockchainPart ssc)
instance Binary (RequestBlock ssc)
instance Binary (RequestBlockchainPart ssc)

instance Ssc ssc => Message (SendBlock ssc) where
    messageName _ = "SendBlock"
    formatMessage = messageName'

instance Ssc ssc => Message (SendBlockHeader ssc) where
    messageName _ = "SendBlockHeader"
    formatMessage = messageName'

instance Ssc ssc => Message (SendBlockchainPart ssc) where
    messageName _ = "SendBlockchainPart"
    formatMessage = messageName'

instance Typeable ssc => Message (RequestBlock ssc) where
    messageName _ = "RequestBlock"
    formatMessage = messageName'

instance Typeable ssc => Message (RequestBlockchainPart ssc) where
    messageName _ = "RequestBlockchainPart"
    formatMessage = messageName'
{'fraction_non_alphanumeric': 0.09223174850610548, 'fraction_numerical': 0.000779423226812159, 'mean_word_length': 3.1847826086956523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5612219', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1122, 'n_words': 347}