Skip to content

Commit

Permalink
Update certififcate JSON friendly rendering
Browse files Browse the repository at this point in the history
Update readTxVotes  to read a VotingEntry which consists of the voter's
voting credential, the governance action id of the proposal the vote is
for and the vote itself
  • Loading branch information
Jimbo4350 committed Aug 22, 2023
1 parent ba1b96b commit 2112469
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ pAnyVote :: ConwayEraOnwards era -> Parser AnyVote
pAnyVote cOnwards =
ConwayOnwardsVote cOnwards
<$> pVoteChoice
<*> pGoveranceActionIdentifier "TxIn of governance action (already on chain)."
<*> pAnyVotingStakeVerificationKeyOrHashOrFile

pAnyVotingStakeVerificationKeyOrHashOrFile :: Parser AnyVotingStakeVerificationKeyOrHashOrFile
pAnyVotingStakeVerificationKeyOrHashOrFile =
_pAnyVotingStakeVerificationKeyOrHashOrFile :: Parser AnyVotingStakeVerificationKeyOrHashOrFile
_pAnyVotingStakeVerificationKeyOrHashOrFile =
asum [ AnyDRepVerificationKeyOrHashOrFile <$> pDRepVerificationKeyOrHashOrFile
, AnyStakePoolVerificationKeyOrHashOrFile <$> pStakePoolVerificationKeyOrHashOrFile
]
Expand Down
37 changes: 25 additions & 12 deletions cardano-cli/src/Cardano/CLI/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cardano.Api.Shelley (Address (ShelleyAddress), Hash (..),
StakeAddress (..), fromShelleyPaymentCredential, fromShelleyScriptHash,
fromShelleyStakeReference, toShelleyLovelace, toShelleyStakeCredential)

import qualified Cardano.Ledger.Conway.TxCert as ConwayLedger
import qualified Cardano.Ledger.Credential as Shelley
import qualified Cardano.Ledger.Shelley.API as Shelley

Expand Down Expand Up @@ -312,6 +313,12 @@ stakeCredJson
-> Aeson.Value
stakeCredJson sbe c = shelleyBasedEraConstraints sbe $ toJSON c

drepCredJson
:: ShelleyBasedEra era
-> Shelley.Credential 'Shelley.DRepRole (Ledger.EraCrypto (ShelleyLedgerEra era))
-> Aeson.Value
drepCredJson sbe c = shelleyBasedEraConstraints sbe $ toJSON c

poolIdJson
:: ShelleyBasedEra era
-> Ledger.KeyHash Ledger.StakePool (Ledger.EraCrypto (ShelleyLedgerEra era))
Expand Down Expand Up @@ -363,7 +370,7 @@ renderCertificate sbe = \case
ConwayCertificate w cert ->
conwayEraOnwardsConstraints w $
case cert of
Ledger.RegDRepTxCert credential coin ->
Ledger.RegDRepTxCert credential coin _TODO -> -- TODO Conway: new StrictMaybe Anchor argument
"Drep registration certificate" .= object
[ "deposit" .= coin
, "certificate" .= conwayToObject w credential
Expand All @@ -373,15 +380,21 @@ renderCertificate sbe = \case
[ "refund" .= coin
, "certificate" .= conwayToObject w credential
]
Ledger.AuthCommitteeHotKeyTxCert (Shelley.KeyHash coldKey) (Shelley.KeyHash hotKey) ->
Ledger.AuthCommitteeHotKeyTxCert coldCred hotCred
| Shelley.ScriptHashObj{} <- coldCred -> error "renderCertificate: TODO Conway era"
| Shelley.ScriptHashObj{} <- hotCred -> error "renderCertificate: TODO Conway era"
| Shelley.KeyHashObj (Shelley.KeyHash coldKey) <- coldCred
, Shelley.KeyHashObj (Shelley.KeyHash hotKey) <- hotCred ->
"Constitutional committee member hot key registration" .= object
["cold key hash" .= String (textShow coldKey)
, "hot key hash" .= String (textShow hotKey)
]
Ledger.ResignCommitteeColdTxCert (Shelley.KeyHash coldKey) ->
"Constitutional committee cold key resignation" .= object
[ "cold key hash" .= String (textShow coldKey)
, "hot key hash" .= String (textShow hotKey)
]
Ledger.ResignCommitteeColdTxCert cred -> case cred of
Shelley.ScriptHashObj{} -> error "renderCertificate: TODO Conway era"
Shelley.KeyHashObj (Shelley.KeyHash coldKey) ->
"Constitutional committee cold key resignation" .= object
[ "cold key hash" .= String (textShow coldKey)
]
Ledger.RegTxCert stakeCredential ->
"Stake address registration" .= object
[ "stake credential" .= stakeCredJson sbe stakeCredential
Expand Down Expand Up @@ -420,15 +433,15 @@ renderCertificate sbe = \case
[ "stake pool key hash" .= String (textShow kh)
, "epoch" .= epoch
]
Ledger.DelegStakeTxCert stakeCredential (Shelley.KeyHash kh) ->
"Stake address delegation" .= object
[ "stake credential" .= stakeCredJson sbe stakeCredential
, "key hash" .= String (textShow kh)
ConwayLedger.UpdateDRepTxCert drepCredential mbAnchor ->
"Drep certificate update" .= object
[ "Drep credential" .= drepCredJson sbe drepCredential
, "anchor " .= mbAnchor
]
where
conwayToObject :: ()
=> ConwayEraOnwards era
-> Shelley.Credential 'Shelley.Voting (Ledger.EraCrypto (ShelleyLedgerEra era))
-> Shelley.Credential 'Shelley.DRepRole (Ledger.EraCrypto (ShelleyLedgerEra era))
-> Aeson.Value
conwayToObject w' =
conwayEraOnwardsConstraints w' $
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Cardano.CLI.Types.Key (VerificationKeyOrHashOrFile,
import qualified Cardano.CLI.Types.Output as O
import Cardano.Crypto.Hash (hashToBytesAsHex)
import qualified Cardano.Crypto.Hash.Blake2b as Blake2b
import qualified Cardano.Ledger.BaseTypes as L
import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Crypto as Crypto
import Cardano.Ledger.Keys (KeyHash (..), KeyRole (..))
Expand Down Expand Up @@ -70,7 +71,6 @@ import Data.Aeson as Aeson
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Aeson.Types as Aeson
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Coerce (coerce)
import Data.Function ((&))
Expand Down Expand Up @@ -160,7 +160,7 @@ runQueryConstitutionHash socketPath (AnyConsensusModeParams cModeParams) network
where
writeConstitutionHash
:: Maybe (File () Out)
-> Maybe (SafeHash StandardCrypto ByteString)
-> Maybe (SafeHash StandardCrypto L.AnchorData)
-> ExceptT ShelleyQueryCmdError IO ()
writeConstitutionHash mOutFile' cHash =
case mOutFile' of
Expand Down
14 changes: 11 additions & 3 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Function ((&))
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Word
Expand Down Expand Up @@ -742,14 +743,21 @@ readTxVotes :: ()
-> IO (Either VoteError (TxVotes era))
readTxVotes _ [] = return $ Right TxVotesNone
readTxVotes w files = runExceptT $ do
TxVotes w <$> forM files (ExceptT . readVoteFile w)
TxVotes w . Map.fromList . map entryToAssoc <$> forM files (ExceptT . readVoteFile w)
where
entryToAssoc :: VotingEntry era -> ((Voter era, GovernanceActionId era), VotingProcedure era)
entryToAssoc VotingEntry
{ votingEntryVoter = voter
, votingEntryGovActionId = govActId
, votingEntryVotingProcedure = vproc
} = ((voter, govActId), vproc)

readVoteFile
:: ConwayEraOnwards era
-> VoteFile In
-> IO (Either VoteError (VotingProcedure era))
-> IO (Either VoteError (VotingEntry era))
readVoteFile w fp =
first VoteErrorFile <$> conwayEraOnwardsConstraints w (readFileTextEnvelope AsVote fp)
first VoteErrorFile <$> conwayEraOnwardsConstraints w (readFileTextEnvelope AsVotingEntry fp)

data ConstitutionError
= ConstitutionErrorFile (FileError TextEnvelopeError)
Expand Down

0 comments on commit 2112469

Please sign in to comment.