Skip to content

Commit

Permalink
Add helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Aug 21, 2023
1 parent 513de10 commit 64738a5
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ module Cardano.Api.Governance.Actions.VotingProcedure where
import Cardano.Api.Address
import Cardano.Api.Eras
import Cardano.Api.Feature.ConwayEraOnwards
import Cardano.Api.Governance.Actions.ProposalProcedure
import Cardano.Api.HasTypeProxy
import Cardano.Api.Keys.Shelley
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Script
import Cardano.Api.SerialiseCBOR (FromCBOR (fromCBOR), SerialiseAsCBOR (..),
ToCBOR (toCBOR))
Expand All @@ -29,17 +31,15 @@ import Cardano.Api.TxIn

import qualified Cardano.Binary as CBOR
import qualified Cardano.Ledger.Binary.Plain as Plain
import qualified Cardano.Ledger.Conway.Governance as Ledger
import Cardano.Ledger.Core (EraCrypto)
import qualified Cardano.Ledger.Core as Ledger
import qualified Cardano.Ledger.Core as Shelley
import qualified Cardano.Ledger.Credential as Ledger
import Cardano.Ledger.Crypto (StandardCrypto)
import Cardano.Ledger.Keys (HasKeyRole (..), KeyRole (DRepRole))

import Data.ByteString.Lazy (ByteString)
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict
import Data.Text (Text)
import qualified Data.Text.Encoding as Text
import Data.Word (Word32)

-- | A representation of whether the era supports tx voting on governance actions.
Expand Down Expand Up @@ -72,6 +72,8 @@ instance IsShelleyBasedEra era => FromCBOR (GovernanceActionId era) where
!v <- shelleyBasedEraConstraints (shelleyBasedEra @era) $ Ledger.fromEraCBOR @(ShelleyLedgerEra era)
return $ GovernanceActionId v


{-# DEPRECATED makeGoveranceActionId "Use createGovernanceActionId" #-}
makeGoveranceActionId
:: ShelleyBasedEra era
-> TxId
Expand Down Expand Up @@ -207,20 +209,19 @@ instance IsShelleyBasedEra era => FromCBOR (VotingCredential era) where
createVotingProcedure
:: ShelleyBasedEra era
-> Vote
-> Voter era
-> GovernanceActionId era
-> Maybe (Ledger.Url, Text) -- ^ Anchor
-> VotingProcedure era
createVotingProcedure sbe vChoice _TODO1 (GovernanceActionId _TODO2) =
shelleyBasedEraConstraints sbe
$ VotingProcedure $ Ledger.VotingProcedure
{ Ledger.vProcVote = toVote vChoice
, Ledger.vProcAnchor = SNothing -- TODO: Conway
}
createVotingProcedure sbe vChoice mProposalAnchor =
let proposalAnchor = fmap Text.encodeUtf8 <$> mProposalAnchor
in shelleyBasedEraConstraints sbe
$ VotingProcedure $ Ledger.VotingProcedure
{ Ledger.vProcVote = toVote vChoice
, Ledger.vProcAnchor = Ledger.maybeToStrictMaybe $ uncurry createAnchor <$> proposalAnchor
}

newtype VotingProcedure era = VotingProcedure
{ unVotingProcedure :: Ledger.VotingProcedure (ShelleyLedgerEra era)
}
deriving (Show, Eq)
} deriving (Show, Eq)

instance IsShelleyBasedEra era => ToCBOR (VotingProcedure era) where
toCBOR (VotingProcedure vp) = shelleyBasedEraConstraints sbe $ Shelley.toEraCBOR @(ShelleyLedgerEra era) vp
Expand Down

0 comments on commit 64738a5

Please sign in to comment.