-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add messages handling to quicheck model
- Loading branch information
1 parent
43995fb
commit 1d31249
Showing
5 changed files
with
109 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
|
||
module Peras.Block where | ||
|
||
import Data.ByteString as BS | ||
import Numeric.Natural (Natural) | ||
|
||
newtype PartyId = PartyId {unPartyId :: ByteString} | ||
deriving (Eq, Show, Ord) | ||
|
||
newtype BlockId = BlockId {unBlockId :: ByteString} | ||
deriving (Eq, Show, Ord) | ||
|
||
newtype Slot = Slot Natural | ||
deriving (Eq, Show, Num, Ord) | ||
|
||
data Block t = Block | ||
{ blockId :: BlockId | ||
, slotNumber :: Slot | ||
, creatorId :: PartyId | ||
, parentBlock :: BlockId | ||
, includedVotes :: t | ||
, payload :: ByteString | ||
} | ||
deriving (Eq, Show, Ord) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Peras.Chain where | ||
|
||
import Peras.Block (Block) | ||
|
||
data Chain t = Genesis | ||
| Cons (Block t) (Chain t) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Peras.Crypto where | ||
|
||
import Data.ByteString as BS | ||
|
||
newtype Hash = Hash{hash :: ByteString} | ||
|
||
newtype MembershipProof = MembershipProof{proofM :: ByteString} | ||
|
||
newtype LeadershipProof = LeadershipProof{proof :: ByteString} | ||
|
||
newtype Signature = Signature{signature :: ByteString} | ||
|
||
newtype VerificationKey = VerificationKey{verificationKey :: | ||
ByteString} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Peras.Message where | ||
|
||
import Data.ByteString (ByteString) | ||
import Data.Maybe (mapMaybe) | ||
import Peras.Block (Block, BlockId, Slot) | ||
|
||
newtype NodeId = NodeId {nodeId :: ByteString} | ||
deriving (Eq, Show, Ord) | ||
|
||
data Message votes | ||
= NextSlot Slot | ||
| RollForward (Block votes) | ||
| RollBack BlockId | ||
deriving (Eq, Show) | ||
|
||
selectBlocks :: [Message ()] -> [Block ()] | ||
selectBlocks = mapMaybe isRollForward | ||
|
||
isRollForward :: Message () -> Maybe (Block ()) | ||
isRollForward = \case | ||
RollForward block -> Just block | ||
_other -> Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters