| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.Governance.Voting
Description
Assemble role-aware votes on governance actions. Validate identities once,
create a VotingProcedure with an optional explanation, and associate it with
a voter/action pair. Repeated pairs fail explicitly rather than lose votes.
import qualified Cometa.Governance.ActionId as ActionId import qualified Cometa.Governance.Voting as Voting support :: Voting.Voter -> ActionId.ActionId -> Voting.VotingProcedures support voter action = Voting.singleton voter action (Voting.VotingProcedure Voting.Yes Nothing)
Synopsis
- data Vote
- data Voter
- data VotingProcedure = VotingProcedure {}
- encodeVoter :: Voter -> ByteString
- decodeVoter :: ByteString -> Either Error Voter
- encodeProcedure :: VotingProcedure -> ByteString
- decodeProcedure :: ByteString -> Either Error VotingProcedure
- data VotingProcedures
- empty :: VotingProcedures
- singleton :: Voter -> ActionId -> VotingProcedure -> VotingProcedures
- fromList :: [(Voter, ActionId, VotingProcedure)] -> Either Error VotingProcedures
- toList :: VotingProcedures -> [(Voter, ActionId, VotingProcedure)]
- insert :: Voter -> ActionId -> VotingProcedure -> VotingProcedures -> Either Error VotingProcedures
- lookup :: Voter -> ActionId -> VotingProcedures -> Maybe VotingProcedure
- merge :: VotingProcedures -> VotingProcedures -> Either Error VotingProcedures
- data EncodedVotingProcedures
- encodeCbor :: VotingProcedures -> ByteString
- decodeCbor :: ByteString -> Either Error EncodedVotingProcedures
- fromVotingProcedures :: VotingProcedures -> EncodedVotingProcedures
- toVotingProcedures :: EncodedVotingProcedures -> VotingProcedures
- toCbor :: EncodedVotingProcedures -> ByteString
Choices and authorities
A governance voting choice. Ordering follows CBOR codes: No=0, Yes=1, Abstain=2. Abstention is an explicit choice, distinct from an absent vote.
Authority casting a vote. Committee votes use the hot credential; stake pools have key authorities only. Ordering follows native voter codes (committee keyscript, DRep keyscript, pool key), then exact hash bytes.
Constructors
| CommitteeVoter !(Credential CommitteeHot) | Constitutional committee hot key or script. |
| DRepVoter !(Credential DRep) | DRep key or script; special delegation targets cannot vote. |
| StakePoolVoter !(KeyHash StakePool) | Stake pool verification-key hash. |
data VotingProcedure Source #
A voting choice and optional explanation. Nothing encodes as CBOR null;
a present anchor carries a validated metadata location and payload hash.
Constructors
| VotingProcedure | |
Instances
| Show VotingProcedure Source # | |
Defined in Cometa.Internal.Governance Methods showsPrec :: Int -> VotingProcedure -> ShowS # show :: VotingProcedure -> String # showList :: [VotingProcedure] -> ShowS # | |
| Eq VotingProcedure Source # | |
Defined in Cometa.Internal.Governance Methods (==) :: VotingProcedure -> VotingProcedure -> Bool # (/=) :: VotingProcedure -> VotingProcedure -> Bool # | |
| Ord VotingProcedure Source # | |
Defined in Cometa.Internal.Governance Methods compare :: VotingProcedure -> VotingProcedure -> Ordering # (<) :: VotingProcedure -> VotingProcedure -> Bool # (<=) :: VotingProcedure -> VotingProcedure -> Bool # (>) :: VotingProcedure -> VotingProcedure -> Bool # (>=) :: VotingProcedure -> VotingProcedure -> Bool # max :: VotingProcedure -> VotingProcedure -> VotingProcedure # min :: VotingProcedure -> VotingProcedure -> VotingProcedure # | |
encodeVoter :: Voter -> ByteString Source #
Encode a voter as definite CBOR [kind, hash bytes]. Kinds are 0 committee
key, 1 committee script, 2 DRep key, 3 DRep script, and 4 stake pool key.
decodeVoter :: ByteString -> Either Error Voter Source #
Decode exactly one voter, enforcing kind, arity, and 28-byte hash length.
Definite/indefinite arrays and nonminimal codes are accepted. Invalid input
or trailing bytes returns InvalidGovernanceCbor. The original
encoding is not retained.
encodeProcedure :: VotingProcedure -> ByteString Source #
Encode a procedure as definite CBOR [choice, anchor or null], using
choice codes 0 (No), 1 (Yes) and 2 (Abstain).
decodeProcedure :: ByteString -> Either Error VotingProcedure Source #
Decode exactly one procedure with a validated optional anchor. Invalid
choice, arity, anchor, or trailing bytes returns
InvalidGovernanceCbor. Definite/indefinite arrays and nonminimal
codes are accepted; original encoding is not retained.
Unique voter/action collections
data VotingProcedures Source #
At most one procedure for each voter/action pair. Empty is valid; stored
voters always have at least one procedure. Equality is semantic; ordering
compares sorted voter/action entries and their procedures. Show is diagnostic.
Instances
| Show VotingProcedures Source # | |
Defined in Cometa.Internal.Governance Methods showsPrec :: Int -> VotingProcedures -> ShowS # show :: VotingProcedures -> String # showList :: [VotingProcedures] -> ShowS # | |
| Eq VotingProcedures Source # | |
Defined in Cometa.Internal.Governance Methods (==) :: VotingProcedures -> VotingProcedures -> Bool # (/=) :: VotingProcedures -> VotingProcedures -> Bool # | |
| Ord VotingProcedures Source # | |
Defined in Cometa.Internal.Governance Methods compare :: VotingProcedures -> VotingProcedures -> Ordering # (<) :: VotingProcedures -> VotingProcedures -> Bool # (<=) :: VotingProcedures -> VotingProcedures -> Bool # (>) :: VotingProcedures -> VotingProcedures -> Bool # (>=) :: VotingProcedures -> VotingProcedures -> Bool # max :: VotingProcedures -> VotingProcedures -> VotingProcedures # min :: VotingProcedures -> VotingProcedures -> VotingProcedures # | |
empty :: VotingProcedures Source #
No votes.
singleton :: Voter -> ActionId -> VotingProcedure -> VotingProcedures Source #
One voter casting one procedure on one action. All arguments are validated domain values, so assembly cannot fail.
fromList :: [(Voter, ActionId, VotingProcedure)] -> Either Error VotingProcedures Source #
Assemble triples in any order. Repeating a voter/action pair returns
DuplicateGovernanceVote, even when the procedures agree. No vote is discarded.
toList :: VotingProcedures -> [(Voter, ActionId, VotingProcedure)] Source #
Entries sorted by voter kindhash, then transaction hashindex. Input insertion order is not retained by this semantic collection.
insert :: Voter -> ActionId -> VotingProcedure -> VotingProcedures -> Either Error VotingProcedures Source #
Add a vote, rejecting an existing voter/action pair with
DuplicateGovernanceVote. Other votes remain unchanged.
lookup :: Voter -> ActionId -> VotingProcedures -> Maybe VotingProcedure Source #
Find the procedure for a voter/action pair; absence is legitimate.
merge :: VotingProcedures -> VotingProcedures -> Either Error VotingProcedures Source #
Combine disjoint voter/action pairs. Any overlap returns
DuplicateGovernanceVote, even when both votes agree. Successful merge is
associative and commutative, with empty as its identity.
Encoding identity
data EncodedVotingProcedures Source #
Voting data with its exact original CBOR encoding. Equality and ordering
compare encoded bytes; toVotingProcedures permits semantic comparison.
Imported map order and nonminimal encodings remain observable through toCbor.
Instances
encodeCbor :: VotingProcedures -> ByteString Source #
Encode fresh nested maps ordered by voter kind/hash, then transaction
hash/index, using definite containers and shortest integers. Re-encoding
inspected external data can change its containing transaction identity;
toCbor preserves the imported encoding instead.
decodeCbor :: ByteString -> Either Error EncodedVotingProcedures Source #
Decode exactly one nested voting map, preserving its exact input bytes.
Definite/indefinite containers and nonminimal encodings are accepted. Duplicate
voter keys, duplicate action keys within a voter, and empty inner maps are
rejected. Malformed CBOR, invalid schema, bounds, UTF-8, or trailing bytes
returns InvalidGovernanceCbor.
fromVotingProcedures :: VotingProcedures -> EncodedVotingProcedures Source #
Assign fresh minimal, sorted CBOR to a semantic collection.
toVotingProcedures :: EncodedVotingProcedures -> VotingProcedures Source #
Inspect votes without changing their preserved encoding.
toCbor :: EncodedVotingProcedures -> ByteString Source #
The exact imported encoding, or the fresh encoding assigned by
fromVotingProcedures.