Skip to content

Commit

Permalink
Merge pull request #555 from IntersectMBO/ch/clarify-all-or-some-flag…
Browse files Browse the repository at this point in the history
…s-drep

Clarify DRep queries with an all-or-some logic
  • Loading branch information
carlhammann authored Jan 10, 2024
2 parents 6386a51 + 76314a8 commit 05c4001
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 104 deletions.
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ data QueryDRepStateCmdArgs era = QueryDRepStateCmdArgs
, nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, drepKeys :: ![VerificationKeyOrHashOrFile DRepKey]
, drepKeys :: !(AllOrOnly (VerificationKeyOrHashOrFile DRepKey))
, mOutFile :: !(Maybe (File () Out))
} deriving Show

Expand All @@ -196,7 +196,7 @@ data QueryDRepStakeDistributionCmdArgs era = QueryDRepStakeDistributionCmdArgs
, nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, drepKeys :: ![VerificationKeyOrHashOrFile DRepKey]
, drepKeys :: !(AllOrOnly (VerificationKeyOrHashOrFile DRepKey))
, mOutFile :: !(Maybe (File () Out))
} deriving Show

Expand Down
85 changes: 9 additions & 76 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -937,55 +937,6 @@ pStakePoolVerificationKeyOrHashOrFile prefix =
, VerificationKeyHash <$> pStakePoolVerificationKeyHash prefix
]

pCombinedStakePoolVerificationKeyOrHashOrFile
:: Parser (VerificationKeyOrHashOrFile StakePoolKey)
pCombinedStakePoolVerificationKeyOrHashOrFile =
asum
[ VerificationKeyOrFile <$> pCombinedStakePoolVerificationKeyOrFile
, VerificationKeyHash <$> pCombinedStakePoolVerificationKeyHash
]

pCombinedStakePoolVerificationKeyOrFile :: Parser (VerificationKeyOrFile StakePoolKey)
pCombinedStakePoolVerificationKeyOrFile =
asum
[ VerificationKeyValue <$> pCombinedStakePoolVerificationKey
, VerificationKeyFilePath <$> pCombinedStakePoolVerificationKeyFile
]

pCombinedStakePoolVerificationKeyHash :: Parser (Hash StakePoolKey)
pCombinedStakePoolVerificationKeyHash =
Opt.option (pBech32KeyHash AsStakePoolKey <|> pHexHash AsStakePoolKey) $ mconcat
[ Opt.long "combined-stake-pool-id"
, Opt.metavar "STAKE_POOL_ID"
, Opt.help $ mconcat
[ "Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded). "
, "Zero or more occurences of this option is allowed."
]
]

pCombinedStakePoolVerificationKey :: Parser (VerificationKey StakePoolKey)
pCombinedStakePoolVerificationKey =
Opt.option (readVerificationKey AsStakePoolKey) $ mconcat
[ Opt.long "combined-stake-pool-verification-key"
, Opt.metavar "STRING"
, Opt.help "Stake pool verification key (Bech32 or hex-encoded)."
]

pCombinedStakePoolVerificationKeyFile :: Parser (VerificationKeyFile In)
pCombinedStakePoolVerificationKeyFile =
File <$> asum
[ Opt.strOption $ mconcat
[ Opt.long "combined-cold-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the stake pool verification key."
, Opt.completer (Opt.bashCompleter "file")
]
, Opt.strOption $ mconcat
[ Opt.long "stake-pool-verification-key-file"
, Opt.internal
]
]

--------------------------------------------------------------------------------

pCBORInFile :: Parser FilePath
Expand Down Expand Up @@ -3113,39 +3064,21 @@ pDRepVerificationKeyOrHashOrFile =
, VerificationKeyHash <$> pDRepVerificationKeyHash
]

pCombinedDRepVerificationKey :: Parser (VerificationKey DRepKey)
pCombinedDRepVerificationKey =
Opt.option (readVerificationKey AsDRepKey) $ mconcat
[ Opt.long "combined-drep-verification-key"
, Opt.metavar "STRING"
, Opt.help "DRep verification key (Bech32 or hex-encoded)."
]

pCombinedDRepVerificationKeyOrFile :: Parser (VerificationKeyOrFile DRepKey)
pCombinedDRepVerificationKeyOrFile =
asum
[ VerificationKeyValue <$> pCombinedDRepVerificationKey
, VerificationKeyFilePath <$> pCombinedDRepVerificationKeyFile
]

pCombinedDRepVerificationKeyFile :: Parser (VerificationKeyFile In)
pCombinedDRepVerificationKeyFile =
fmap File . Opt.strOption $ mconcat
[ Opt.long "combined-drep-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the DRep verification key."
, Opt.completer (Opt.bashCompleter "file")
]
pAllOrOnlyDRepVerificationKeyOrHashOrFile
:: Parser (AllOrOnly (VerificationKeyOrHashOrFile DRepKey))
pAllOrOnlyDRepVerificationKeyOrHashOrFile = pAll <|> pOnly
where pOnly = Only <$> some pDRepVerificationKeyOrHashOrFile
pAll = Opt.flag' All $ mconcat
[ Opt.long "all-dreps"
, Opt.help "Query for all DReps."
]

pDRepVerificationKeyHash :: Parser (Hash DRepKey)
pDRepVerificationKeyHash =
Opt.option (pBech32KeyHash AsDRepKey <|> pHexHash AsDRepKey) $ mconcat
[ Opt.long "drep-key-hash"
, Opt.metavar "HASH"
, Opt.help $ mconcat
[ "DRep verification key hash (either Bech32-encoded or hex-encoded). "
, "Zero or more occurences of this option is allowed."
]
, Opt.help "DRep verification key hash (either Bech32-encoded or hex-encoded)."
]

pDRepVerificationKey :: Parser (VerificationKey DRepKey)
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ pQueryDRepStateCmd era envCli = do
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> many pDRepVerificationKeyOrHashOrFile
<*> pAllOrOnlyDRepVerificationKeyOrHashOrFile
<*> optional pOutputFile

pQueryDRepStakeDistributionCmd :: ()
Expand All @@ -341,7 +341,7 @@ pQueryDRepStakeDistributionCmd era envCli = do
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> many pDRepVerificationKeyOrHashOrFile
<*> pAllOrOnlyDRepVerificationKeyOrHashOrFile
<*> optional pOutputFile

pQueryGetCommitteeStateCmd :: ()
Expand Down
10 changes: 8 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1393,11 +1393,14 @@ runQueryDRepState
, Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
, Cmd.drepKeys = drepKeys
, Cmd.drepKeys = drepKeys'
, Cmd.mOutFile
} = conwayEraOnwardsConstraints eon $ do
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath

let drepKeys = case drepKeys' of
All -> []
Only l -> l
drepCreds <- Set.fromList <$> mapM (firstExceptT QueryCmdDRepKeyError . getDRepCredentialFromVerKeyHashOrFile) drepKeys

drepState <- runQuery localNodeConnInfo $ queryDRepState eon drepCreds
Expand All @@ -1419,14 +1422,17 @@ runQueryDRepStakeDistribution
, Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
, Cmd.drepKeys = drepKeys
, Cmd.drepKeys = drepKeys'
, Cmd.mOutFile
} = conwayEraOnwardsConstraints eon $ do
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath

let drepFromVrfKey = fmap Ledger.DRepCredential
. firstExceptT QueryCmdDRepKeyError
. getDRepCredentialFromVerKeyHashOrFile
drepKeys = case drepKeys' of
All -> []
Only l -> l
dreps <- Set.fromList <$> mapM drepFromVrfKey drepKeys

drepStakeDistribution <- runQuery localNodeConnInfo $ queryDRepStakeDistribution eon dreps
Expand Down
14 changes: 10 additions & 4 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -6697,10 +6697,13 @@ Usage: cardano-cli conway query drep-state --socket-path SOCKET_PATH
( --mainnet
| --testnet-magic NATURAL
)
[ --drep-verification-key STRING
( --all-dreps
|
( --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
]
)
)
[--out-file FILE]

Get the DRep state. If no DRep credentials are provided, return states for all
Expand All @@ -6713,10 +6716,13 @@ Usage: cardano-cli conway query drep-stake-distribution
( --mainnet
| --testnet-magic NATURAL
)
[ --drep-verification-key STRING
( --all-dreps
|
( --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
]
)
)
[--out-file FILE]

Get the DRep stake distribution. If no DRep credentials are provided, return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Available options:
--drep-verification-key-file FILE
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded). Zero or more occurences of this option
is allowed.
hex-encoded).
--key-reg-deposit-amt NATURAL
Key registration deposit amount.
--drep-metadata-url TEXT DRep anchor URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ Available options:
--drep-verification-key-file FILE
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded). Zero or more occurences of this option
is allowed.
hex-encoded).
--deposit-amt LOVELACE DRep deposit amount (same at registration and
retirement).
--out-file FILE The output file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ Available options:
--drep-verification-key-file FILE
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded). Zero or more occurences of this option
is allowed.
hex-encoded).
--stake-pool-verification-key STRING
Stake pool verification key (Bech32 or hex-encoded).
--cold-verification-key-file FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ Usage: cardano-cli conway query drep-stake-distribution
( --mainnet
| --testnet-magic NATURAL
)
[ --drep-verification-key STRING
( --all-dreps
|
( --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
]
)
)
[--out-file FILE]

Get the DRep stake distribution. If no DRep credentials are provided, return
Expand All @@ -28,12 +31,12 @@ Available options:
CARDANO_NODE_NETWORK_ID environment variable
--testnet-magic NATURAL Specify a testnet magic id. This overrides the
CARDANO_NODE_NETWORK_ID environment variable
--all-dreps Query for all DReps.
--drep-verification-key STRING
DRep verification key (Bech32 or hex-encoded).
--drep-verification-key-file FILE
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded). Zero or more occurences of this option
is allowed.
hex-encoded).
--out-file FILE The output file.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ Usage: cardano-cli conway query drep-state --socket-path SOCKET_PATH
( --mainnet
| --testnet-magic NATURAL
)
[ --drep-verification-key STRING
( --all-dreps
|
( --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
]
)
)
[--out-file FILE]

Get the DRep state. If no DRep credentials are provided, return states for all
Expand All @@ -27,12 +30,12 @@ Available options:
CARDANO_NODE_NETWORK_ID environment variable
--testnet-magic NATURAL Specify a testnet magic id. This overrides the
CARDANO_NODE_NETWORK_ID environment variable
--all-dreps Query for all DReps.
--drep-verification-key STRING
DRep verification key (Bech32 or hex-encoded).
--drep-verification-key-file FILE
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded). Zero or more occurences of this option
is allowed.
hex-encoded).
--out-file FILE The output file.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ Available options:
--drep-verification-key-file FILE
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded). Zero or more occurences of this option
is allowed.
hex-encoded).
--always-abstain Abstain from voting on all proposals.
--always-no-confidence Always vote no confidence
--out-file FILE The output file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ Available options:
--drep-verification-key-file FILE
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded). Zero or more occurences of this option
is allowed.
hex-encoded).
--always-abstain Abstain from voting on all proposals.
--always-no-confidence Always vote no confidence
--out-file FILE The output file.
Expand Down

0 comments on commit 05c4001

Please sign in to comment.