Skip to content

Commit

Permalink
Merge pull request #666 from IntersectMBO/query-drep-state-by-scripthash
Browse files Browse the repository at this point in the history
Support querying drep-state by script hash
  • Loading branch information
palas authored Mar 26, 2024
2 parents 644294c + 22721be commit 7592b24
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 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 @@ -207,7 +207,7 @@ data QueryDRepStateCmdArgs era = QueryDRepStateCmdArgs
, nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, drepKeys :: !(AllOrOnly (VerificationKeyOrHashOrFile DRepKey))
, drepHashSources :: !(AllOrOnly DRepHashSource)
, includeStake :: !IncludeStake
, target :: !(Consensus.Target ChainPoint)
, mOutFile :: !(Maybe (File () Out))
Expand All @@ -223,7 +223,7 @@ data QueryDRepStakeDistributionCmdArgs era = QueryDRepStakeDistributionCmdArgs
, nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, drepKeys :: !(AllOrOnly (VerificationKeyOrHashOrFile DRepKey))
, drepHashSources :: !(AllOrOnly DRepHashSource)
, target :: !(Consensus.Target ChainPoint)
, mOutFile :: !(Maybe (File () Out))
} deriving Show
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3212,10 +3212,10 @@ pDRepVerificationKeyOrHashOrFileOrScriptHash =
"Cold Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

pAllOrOnlyDRepVerificationKeyOrHashOrFile
:: Parser (AllOrOnly (VerificationKeyOrHashOrFile DRepKey))
pAllOrOnlyDRepVerificationKeyOrHashOrFile = pAll <|> pOnly
where pOnly = Only <$> some pDRepVerificationKeyOrHashOrFile
pAllOrOnlyDRepHashSoure
:: Parser (AllOrOnly DRepHashSource)
pAllOrOnlyDRepHashSoure = pAll <|> pOnly
where pOnly = Only <$> some pDRepHashSource
pAll = Opt.flag' All $ mconcat
[ Opt.long "all-dreps"
, Opt.help "Query for all DReps."
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 @@ -339,7 +339,7 @@ pQueryDRepStateCmd era envCli = do
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> pAllOrOnlyDRepVerificationKeyOrHashOrFile
<*> pAllOrOnlyDRepHashSoure
<*> Opt.flag WithStake NoStake (mconcat
[ Opt.long "include-stake"
, Opt.help $ mconcat
Expand Down Expand Up @@ -369,7 +369,7 @@ pQueryDRepStakeDistributionCmd era envCli = do
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> pAllOrOnlyDRepVerificationKeyOrHashOrFile
<*> pAllOrOnlyDRepHashSoure
<*> pTarget era
<*> optional pOutputFile

Expand Down
25 changes: 12 additions & 13 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))
import qualified Cardano.CLI.EraBased.Commands.Query as Cmd
import Cardano.CLI.EraBased.Run.CreateTestnetData (readAndDecodeGenesisFile)
import Cardano.CLI.Helpers
import Cardano.CLI.Read
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.NodeEraMismatchError
import Cardano.CLI.Types.Errors.QueryCmdError
Expand Down Expand Up @@ -1411,17 +1410,17 @@ runQueryDRepState
, Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
, Cmd.drepKeys = drepKeys'
, Cmd.drepHashSources = drepHashSources'
, Cmd.includeStake
, Cmd.target
, Cmd.mOutFile
} = conwayEraOnwardsConstraints eon $ do
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath

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

drepState <- runQuery localNodeConnInfo target $ queryDRepState eon $ Set.fromList drepCreds

Expand Down Expand Up @@ -1457,19 +1456,19 @@ runQueryDRepStakeDistribution
, Cmd.nodeSocketPath
, Cmd.consensusModeParams
, Cmd.networkId
, Cmd.drepKeys = drepKeys'
, Cmd.drepHashSources = drepHashSources'
, Cmd.target
, Cmd.mOutFile
} = conwayEraOnwardsConstraints eon $ do
let localNodeConnInfo = LocalNodeConnectInfo consensusModeParams networkId nodeSocketPath

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

drepStakeDistribution <- runQuery localNodeConnInfo target $ queryDRepStakeDistribution eon dreps
writeOutput mOutFile $
Expand Down
6 changes: 4 additions & 2 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -6860,7 +6860,8 @@ Usage: cardano-cli conway query drep-state --socket-path SOCKET_PATH
)
( --all-dreps
|
( --drep-verification-key STRING
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
)
Expand All @@ -6880,7 +6881,8 @@ Usage: cardano-cli conway query drep-stake-distribution
)
( --all-dreps
|
( --drep-verification-key STRING
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Usage: cardano-cli conway query drep-stake-distribution
)
( --all-dreps
|
( --drep-verification-key STRING
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
)
Expand All @@ -34,6 +35,8 @@ Available options:
--testnet-magic NATURAL Specify a testnet magic id. This overrides the
CARDANO_NODE_NETWORK_ID environment variable
--all-dreps Query for all DReps.
--drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with
"cardano-cli conway governance hash script ...".
--drep-verification-key STRING
DRep verification key (Bech32 or hex-encoded).
--drep-verification-key-file FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Usage: cardano-cli conway query drep-state --socket-path SOCKET_PATH
)
( --all-dreps
|
( --drep-verification-key STRING
( --drep-script-hash HASH
| --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
)
Expand All @@ -32,6 +33,8 @@ Available options:
--testnet-magic NATURAL Specify a testnet magic id. This overrides the
CARDANO_NODE_NETWORK_ID environment variable
--all-dreps Query for all DReps.
--drep-script-hash HASH DRep script hash (hex-encoded). Obtain it with
"cardano-cli conway governance hash script ...".
--drep-verification-key STRING
DRep verification key (Bech32 or hex-encoded).
--drep-verification-key-file FILE
Expand Down

0 comments on commit 7592b24

Please sign in to comment.