plutus-use-cases-1.2.0.0: Collection of smart contracts to develop the plutus/wallet interface
Safe HaskellNone
LanguageHaskell2010

Plutus.Contracts.Governance

Description

A basic governance contract in Plutus.

Synopsis

Documentation

  • When the contract starts it produces a number of tokens that represent voting rights.
  • Holders of those tokens can propose changes to the state of the contract and vote on them.
  • After a certain period of time the voting ends and the proposal is rejected or accepted.

contract :: AsGovError e => Params -> Contract () Schema e () Source #

The main contract for creating a new law and for voting on proposals.

proposalContract :: AsGovError e => Params -> Address -> Proposal -> Contract () EmptySchema e () Source #

The contract for proposing changes to a law.

data Params Source #

The governace contract parameters.

Constructors

Params 

Fields

  • baseTokenName :: TokenName

    The token names that allow voting are generated by adding an increasing number to the base token name. See mkTokenName.

  • initialHolders :: [Address]

    The public key hashes of the initial holders of the voting tokens.

  • requiredVotes :: Integer

    The number of votes in favor required for a proposal to be accepted.

Instances

Instances details
Lift DefaultUni Params Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

lift :: Params -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni Params Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

typeRep :: Proxy Params -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

data Proposal Source #

The parameters for the proposal contract.

Constructors

Proposal 

Fields

  • newLaw :: Law

    The new contents of the law

  • tokenName :: TokenName

    The name of the voting tokens. Only voting token owners are allowed to propose changes.

  • votingDeadline :: POSIXTime

    The time when voting ends and the votes are tallied.

Instances

Instances details
Show Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Generic Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Associated Types

type Rep Proposal :: Type -> Type Source #

FromJSON Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

parseJSON :: Value -> Parser Proposal

parseJSONList :: Value -> Parser [Proposal]

ToJSON Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toJSON :: Proposal -> Value

toEncoding :: Proposal -> Encoding

toJSONList :: [Proposal] -> Value

toEncodingList :: [Proposal] -> Encoding

ToData Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toBuiltinData :: Proposal -> BuiltinData

FromData Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

fromBuiltinData :: BuiltinData -> Maybe Proposal

UnsafeFromData Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

unsafeFromBuiltinData :: BuiltinData -> Proposal

Lift DefaultUni Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

lift :: Proposal -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

typeRep :: Proxy Proposal -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep Proposal Source # 
Instance details

Defined in Plutus.Contracts.Governance

type Rep Proposal = D1 ('MetaData "Proposal" "Plutus.Contracts.Governance" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "Proposal" 'PrefixI 'True) (S1 ('MetaSel ('Just "newLaw") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Law) :*: (S1 ('MetaSel ('Just "tokenName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TokenName) :*: S1 ('MetaSel ('Just "votingDeadline") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 POSIXTime))))

type Schema = Endpoint "new-law" Law .\/ Endpoint "add-vote" (Address, TokenName, Bool) Source #

The endpoints of governance contracts are

  • new-law to create a new law and distribute voting tokens
  • add-vote to vote on a proposal with the name of the voting token and a boolean to vote in favor or against.

mkTokenName :: TokenName -> Integer -> TokenName Source #

Generate a voting token name by tagging on a number after the base token name.

typedValidator :: Params -> TypedValidator GovernanceMachine Source #

mkValidator :: Params -> ValidatorType GovernanceMachine Source #

data GovState Source #

Constructors

GovState 

Fields

Instances

Instances details
Show GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Generic GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Associated Types

type Rep GovState :: Type -> Type Source #

FromJSON GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

parseJSON :: Value -> Parser GovState

parseJSONList :: Value -> Parser [GovState]

ToJSON GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toJSON :: GovState -> Value

toEncoding :: GovState -> Encoding

toJSONList :: [GovState] -> Value

toEncodingList :: [GovState] -> Encoding

ToData GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toBuiltinData :: GovState -> BuiltinData

FromData GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

fromBuiltinData :: BuiltinData -> Maybe GovState

UnsafeFromData GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

unsafeFromBuiltinData :: BuiltinData -> GovState

Lift DefaultUni GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

lift :: GovState -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

typeRep :: Proxy GovState -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep GovState Source # 
Instance details

Defined in Plutus.Contracts.Governance

type Rep GovState = D1 ('MetaData "GovState" "Plutus.Contracts.Governance" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "GovState" 'PrefixI 'True) (S1 ('MetaSel ('Just "law") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Law) :*: (S1 ('MetaSel ('Just "mph") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 MintingPolicyHash) :*: S1 ('MetaSel ('Just "voting") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Voting)))))

newtype Law Source #

Constructors

Law 

Fields

  • unLaw :: BuiltinByteString
     

Instances

Instances details
Eq Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

(==) :: Law -> Law -> Bool Source #

(/=) :: Law -> Law -> Bool Source #

Show Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Generic Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Associated Types

type Rep Law :: Type -> Type Source #

Methods

from :: Law -> Rep Law x Source #

to :: Rep Law x -> Law Source #

FromJSON Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

parseJSON :: Value -> Parser Law

parseJSONList :: Value -> Parser [Law]

ToJSON Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toJSON :: Law -> Value

toEncoding :: Law -> Encoding

toJSONList :: [Law] -> Value

toEncodingList :: [Law] -> Encoding

ToData Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toBuiltinData :: Law -> BuiltinData

FromData Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

fromBuiltinData :: BuiltinData -> Maybe Law

UnsafeFromData Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

unsafeFromBuiltinData :: BuiltinData -> Law

Lift DefaultUni Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

lift :: Law -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

typeRep :: Proxy Law -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep Law Source # 
Instance details

Defined in Plutus.Contracts.Governance

type Rep Law = D1 ('MetaData "Law" "Plutus.Contracts.Governance" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'True) (C1 ('MetaCons "Law" 'PrefixI 'True) (S1 ('MetaSel ('Just "unLaw") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BuiltinByteString)))

data Voting Source #

Constructors

Voting 

Fields

Instances

Instances details
Show Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Generic Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Associated Types

type Rep Voting :: Type -> Type Source #

FromJSON Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

parseJSON :: Value -> Parser Voting

parseJSONList :: Value -> Parser [Voting]

ToJSON Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toJSON :: Voting -> Value

toEncoding :: Voting -> Encoding

toJSONList :: [Voting] -> Value

toEncodingList :: [Voting] -> Encoding

ToData Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toBuiltinData :: Voting -> BuiltinData

FromData Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

fromBuiltinData :: BuiltinData -> Maybe Voting

UnsafeFromData Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

unsafeFromBuiltinData :: BuiltinData -> Voting

Lift DefaultUni Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

lift :: Voting -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

typeRep :: Proxy Voting -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep Voting Source # 
Instance details

Defined in Plutus.Contracts.Governance

type Rep Voting = D1 ('MetaData "Voting" "Plutus.Contracts.Governance" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "Voting" 'PrefixI 'True) (S1 ('MetaSel ('Just "proposal") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Proposal) :*: S1 ('MetaSel ('Just "votes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map TokenName Bool))))

votingValue :: MintingPolicyHash -> TokenName -> Value Source #

data GovError Source #

Instances

Instances details
Eq GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

Show GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

Generic GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

Associated Types

type Rep GovError :: Type -> Type Source #

FromJSON GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

parseJSON :: Value -> Parser GovError

parseJSONList :: Value -> Parser [GovError]

ToJSON GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

toJSON :: GovError -> Value

toEncoding :: GovError -> Encoding

toJSONList :: [GovError] -> Value

toEncodingList :: [GovError] -> Encoding

AsContractError GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

_ContractError :: Prism' GovError ContractError

_WalletContractError :: Prism' GovError WalletAPIError

_ChainIndexContractError :: Prism' GovError (Text, ChainIndexResponse)

_ConstraintResolutionContractError :: Prism' GovError MkTxError

_ToCardanoConvertContractError :: Prism' GovError ToCardanoError

_ResumableContractError :: Prism' GovError MatchingError

_CCheckpointContractError :: Prism' GovError CheckpointError

_EndpointDecodeContractError :: Prism' GovError (EndpointDescription, EndpointValue Value, Text)

_OtherContractError :: Prism' GovError Text

AsSMContractError GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

Methods

_SMContractError :: Prism' GovError SMContractError

_ChooserError :: Prism' GovError Text

_UnableToExtractTransition :: Prism' GovError ()

_SMCContractError :: Prism' GovError ContractError

type Rep GovError Source # 
Instance details

Defined in Plutus.Contracts.Governance

type Rep GovError = D1 ('MetaData "GovError" "Plutus.Contracts.Governance" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "GovContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ContractError)) :+: C1 ('MetaCons "GovStateMachineError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SMContractError)))

covIdx :: CoverageIndex Source #

covIdx' :: CoverageIndex Source #

getLaw :: GovState -> BuiltinByteString Source #