gini-core-0.1.0.0

Safe HaskellNone
LanguageHaskell2010

Gini.Core.Types.Block.Internal

Synopsis

Documentation

data BlockType #

Constructors

Open 
Send 
Receive 
Change 
Instances
Eq BlockType # 
Instance details

Defined in Gini.Core.Types.Block.Internal

Show BlockType # 
Instance details

Defined in Gini.Core.Types.Block.Internal

PersistField BlockType # 
Instance details

Defined in Gini.Core.Types.Block.Internal

Methods

toPersistValue :: BlockType -> PersistValue

fromPersistValue :: PersistValue -> Either Text BlockType

PersistFieldSql BlockType # 
Instance details

Defined in Gini.Core.Types.Block.Internal

Methods

sqlType :: Proxy BlockType -> SqlType

data OpenBlock #

Open block acts as:

  • Initial block on the account chain
  • Receive the initial funds from the source block
  • Set the representative
Instances
Eq OpenBlock # 
Instance details

Defined in Gini.Core.Types.Block.Internal

Show OpenBlock # 
Instance details

Defined in Gini.Core.Types.Block.Internal

data SendBlock #

Contents of a send block

Constructors

SendBlock 

Fields

Instances
Eq SendBlock # 
Instance details

Defined in Gini.Core.Protocol.Types.Block.Internal

Show SendBlock # 
Instance details

Defined in Gini.Core.Protocol.Types.Block.Internal

Generic SendBlock # 
Instance details

Defined in Gini.Core.Protocol.Types.Block.Internal

Associated Types

type Rep SendBlock :: * -> * #

Validity SendBlock # 
Instance details

Defined in Gini.Core.Protocol.Types.Block.Internal

Methods

validate :: SendBlock -> Validation

Persist SendBlock # 
Instance details

Defined in Gini.Core.Protocol.Types.Block.Internal

Methods

put :: SendBlock -> Put ()

get :: Get SendBlock

type Rep SendBlock # 
Instance details

Defined in Gini.Core.Protocol.Types.Block.Internal

type Rep SendBlock = D1 (MetaData "SendBlock" "Gini.Core.Protocol.Types.Block.Internal" "gini-core-0.1.0.0-CYC9q60CJ5rDf5hHcbgY0V" False) (C1 (MetaCons "SendBlock" PrefixI True) (S1 (MetaSel (Just "sendBlockPrevious") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 BlockHash) :*: (S1 (MetaSel (Just "sendBlockDestination") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Account) :*: S1 (MetaSel (Just "sendBlockBalance") SourceUnpack SourceStrict DecidedStrict) (Rec0 Amount))))

data ReceiveBlock #

Receive block:

  • Increases the account balance by recieving money from the source block, which in turn must be a send type block
  • Optionally setting the representative

newtype ChangeBlock #

Change block can only change the representative. But considering that any block can do it we only keep around the previous block hash.

Constructors

ChangeBlock 

data Block (t :: BlockType) (s :: BlockStatus) #

This Block captures everything that the SignedBlock has plus some more information derived from the database. In other words, SignedBlock can always be reconstructed from the Block with the help of toSignedBlock function, but in order to go in the opposite direction we must go through the database and it can only be done when the SignedBlock is being validated and applied to the blockchain.

Here are a few things that are available over the SignedBlock:

  • We know what was the previous balance, so we know how much money being transacted, if any.
  • Unlike the StateBlock, here we know if the money being sent, received or it is a mere change of representative
  • We know at the type level what type of block it is. As such, there is no ambiguous Link field.
  • We know that the Block is valid due to the BlockStatus kind and we even know if it has already been stored (Committed) in the database or not. In words validity of SignedBlock depends not only on it's content but also on the current state of the database, while Block encodes this information at the type level.
  • Representative is available for all blocks, since for any StateBlock reprensentative can be changed and must be present even in the case when such change does not occur.

type family BlockFamily (t :: BlockType) where ... #

A family that relates type level BlockType to the actual block data type

NOTE - SendBlock is reused, since it is the only block type that has the same structure as needed here

handleBlock :: forall t s a. Typeable t => Block t s -> (Block Open s -> a) -> (Block Send s -> a) -> (Block Receive s -> a) -> (Block Change s -> a) -> a #

A way to handle individual block types. See toSignedBlock for an example how to use it.

getBlockType :: forall t s. Typeable t => Block t s -> BlockType #

Bring the type level BlockType to the value level.

toSignedBlock :: Typeable t => Block t s -> SignedBlock #

Convert a validated or commited block into a raw signed block that is ready for serialization and network transmission