<commit_before>{-# LANGUAGE DeriveGeneric #-}

-- | Definitions of the most fundamental types.

module Pos.Types.Types
       (
         NodeId (..)
       , nodeF

       , Coin (..)
       , coinF

       , Address (..)
       , addressF

       , TxIn (..)
       , TxOut (..)
       , Tx (..)
       , Entry (..)
       , Block

       , displayEntry
       ) where

import qualified Data.Text           as T (unwords)
import           Data.Text.Buildable (Buildable)
import qualified Data.Text.Buildable as Buildable
import           Data.Word           (Word32)
import           Formatting          (Format, bprint, build, int, sformat, shown, (%))
import           Universum

import           Pos.Crypto          (Encrypted, Hash, Share)
import           Pos.Util            (Raw)

----------------------------------------------------------------------------
-- Node. TODO: do we need it?
----------------------------------------------------------------------------

newtype NodeId = NodeId
    { getNodeId :: Int
    } deriving (Show, Eq, Ord, Enum)

instance Buildable NodeId where
    build = bprint ("#"%int) . getNodeId

nodeF :: Format r (NodeId -> r)
nodeF = build

----------------------------------------------------------------------------
-- Coin
----------------------------------------------------------------------------

-- | Coin is the least possible unit of currency.
newtype Coin = Coin
    { getCoin :: Int64
    } deriving (Num, Enum, Integral, Show, Ord, Real, Generic, Eq)

instance Buildable Coin where
    build = bprint (int%" coin(s)")

-- | Coin formatter which restricts type.
coinF :: Format r (Coin -> r)
coinF = build

----------------------------------------------------------------------------
-- Address<commit_msg>[POS-7] Add slotting related types<commit_after>{-# LANGUAGE DeriveGeneric #-}

-- | Definitions of the most fundamental types.

module Pos.Types.Types
       (
         NodeId (..)
       , nodeF

       , EpochIndex
       , LocalSlotIndex
       , SlotId (..)

       , Coin (..)
       , coinF

       , Address (..)
       , addressF

       , TxIn (..)
       , TxOut (..)
       , Tx (..)
       , Entry (..)
       , Block

       , displayEntry
       ) where

import qualified Data.Text           as T (unwords)
import           Data.Text.Buildable (Buildable)
import qualified Data.Text.Buildable as Buildable
import           Data.Word           (Word32, Word64)
import           Formatting          (Format, bprint, build, int, sformat, shown, (%))
import           Universum

import           Pos.Crypto          (Encrypted, Hash, Share)
import           Pos.Util            (Raw)

----------------------------------------------------------------------------
-- Node. TODO: do we need it?
----------------------------------------------------------------------------

newtype NodeId = NodeId
    { getNodeId :: Int
    } deriving (Show, Eq, Ord, Enum)

instance Buildable NodeId where
    build = bprint ("#"%int) . getNodeId

nodeF :: Format r (NodeId -> r)
nodeF = build

----------------------------------------------------------------------------
-- Slotting
----------------------------------------------------------------------------

-- | Index of epoch.
type EpochIndex = Word64

-- | Index of slot inside a concrete epoch.
type LocalSlotIndex = Word32

-- | Slot is identified by index of epoch and local index of slot in
-- this epoch. This is a global index
data SlotId = SlotId
    { siEpoch :: !EpochIndex
    , siSlot  :: !LocalSlotIndex
    } deriving (Show, Generic)

----------------------------------------------------------------------------
-- Coin
----------------------------------------------------------------------------

-- | Coin is the least possible unit of currency.
newtype Coin = Coin
    { getCoin :: Int64
    } deriving (Num, Enum, Integral, Show, Ord, Real, Generic, Eq)

instance Buildable Coin where
    build = bprint (int%" coin(s)")

-- | Coin formatter which restricts type.
coinF :: Format r (Coin -> r)
coinF = build

----------------------------------------------------------------------------
-- Address
{'fraction_non_alphanumeric': 0.3083272638990046, 'fraction_numerical': 0.003641660597232338, 'mean_word_length': 1.0528151469855507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5358827', 'n_tokens_mistral': 1047, 'n_tokens_neox': 1008, 'n_words': 322}