Skip to content

Commit

Permalink
Refactor node connection passing to make it use `LocalNodeConnectInfo…
Browse files Browse the repository at this point in the history
…` type
  • Loading branch information
carbolymer committed Jan 28, 2025
1 parent 4c23d68 commit ef697f8
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 217 deletions.
15 changes: 5 additions & 10 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import qualified Cardano.Api.Ledger as L
import qualified Cardano.Api.Network as Consensus
import Cardano.Api.Shelley hiding (QueryInShelleyBasedEra (..))

import Cardano.CLI.Orphans ()
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key

Expand Down Expand Up @@ -75,9 +76,7 @@ data QueryCmds era

-- | Fields that are common to most queries
data QueryCommons = QueryCommons
{ nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
{ nodeConnInfo :: !LocalNodeConnectInfo
, target :: !(Consensus.Target ChainPoint)
}
deriving (Generic, Show)
Expand All @@ -94,9 +93,7 @@ data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs
deriving (Generic, Show)

data QueryProtocolParametersCmdArgs = QueryProtocolParametersCmdArgs
{ nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
{ nodeConnInfo :: !LocalNodeConnectInfo
, mOutFile :: !(Maybe (File () Out))
}
deriving (Generic, Show)
Expand Down Expand Up @@ -177,9 +174,7 @@ data QueryPoolStateCmdArgs = QueryPoolStateCmdArgs
deriving (Generic, Show)

data QueryTxMempoolCmdArgs = QueryTxMempoolCmdArgs
{ nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
{ nodeConnInfo :: !LocalNodeConnectInfo
, query :: !TxMempoolQuery
, mOutFile :: !(Maybe (File () Out))
}
Expand Down Expand Up @@ -284,7 +279,7 @@ renderQueryCmds = \case
"query kes-period-info"
QueryPoolStateCmd{} ->
"query pool-state"
QueryTxMempoolCmd (QueryTxMempoolCmdArgs _ _ _ q _) ->
QueryTxMempoolCmd (QueryTxMempoolCmdArgs _ q _) ->
"query tx-mempool" <> renderTxMempoolQuery q
QuerySlotNumberCmd{} ->
"query slot-number"
Expand Down
9 changes: 3 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Cardano.Api.Shelley
import Cardano.CLI.EraBased.Script.Certificate.Types (CliCertificateScriptRequirements)
import Cardano.CLI.EraBased.Script.Mint.Types
import Cardano.CLI.EraBased.Script.Spend.Types (CliSpendScriptRequirements)
import Cardano.CLI.Orphans ()
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Governance

Expand Down Expand Up @@ -91,9 +92,7 @@ data TransactionBuildRawCmdArgs era = TransactionBuildRawCmdArgs
-- | Like 'TransactionBuildRaw' but without the fee, and with a change output.
data TransactionBuildCmdArgs era = TransactionBuildCmdArgs
{ currentEra :: !(Exp.Era era)
, nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, nodeConnInfo :: !LocalNodeConnectInfo
, mScriptValidity :: !(Maybe ScriptValidity)
-- ^ Mark script as expected to pass or fail validation
, mOverrideWitnesses :: !(Maybe Word)
Expand Down Expand Up @@ -209,9 +208,7 @@ data TransactionSignWitnessCmdArgs = TransactionSignWitnessCmdArgs
deriving Show

data TransactionSubmitCmdArgs = TransactionSubmitCmdArgs
{ nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
{ nodeConnInfo :: !LocalNodeConnectInfo
, txFile :: !FilePath
}
deriving Show
Expand Down
24 changes: 15 additions & 9 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ pQueryProtocolParametersCmd :: EnvCli -> Parser (QueryCmds era)
pQueryProtocolParametersCmd envCli =
fmap QueryProtocolParametersCmd $
QueryProtocolParametersCmdArgs
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<$> ( LocalNodeConnectInfo
<$> pConsensusModeParams
<*> pNetworkId envCli
<*> pSocketPath envCli
)
<*> pMaybeOutputFile

pQueryTipCmd :: ShelleyBasedEra era -> EnvCli -> Parser (QueryCmds era)
Expand Down Expand Up @@ -400,9 +402,11 @@ pQueryTxMempoolCmd :: EnvCli -> Parser (QueryCmds era)
pQueryTxMempoolCmd envCli =
fmap QueryTxMempoolCmd $
QueryTxMempoolCmdArgs
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<$> ( LocalNodeConnectInfo
<$> pConsensusModeParams
<*> pNetworkId envCli
<*> pSocketPath envCli
)
<*> pTxMempoolQuery
<*> pMaybeOutputFile
where
Expand Down Expand Up @@ -699,7 +703,9 @@ pQueryCommons
-> Parser QueryCommons
pQueryCommons w envCli =
QueryCommons
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<$> ( LocalNodeConnectInfo
<$> pConsensusModeParams
<*> pNetworkId envCli
<*> pSocketPath envCli
)
<*> pTarget w
16 changes: 10 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ pTransactionBuildCmd sbe envCli = do
pCmd era' = do
fmap TransactionBuildCmd $
TransactionBuildCmdArgs era'
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<$> ( LocalNodeConnectInfo
<$> pConsensusModeParams
<*> pNetworkId envCli
<*> pSocketPath envCli
)
<*> optional pScriptValidity
<*> optional pWitnessOverride
<*> some (pTxIn sbe AutoBalance)
Expand Down Expand Up @@ -331,9 +333,11 @@ pTransactionSubmit :: EnvCli -> Parser (TransactionCmds era)
pTransactionSubmit envCli =
fmap TransactionSubmitCmd $
TransactionSubmitCmdArgs
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<$> ( LocalNodeConnectInfo
<$> pConsensusModeParams
<*> pNetworkId envCli
<*> pSocketPath envCli
)
<*> pTxSubmitFile

pTransactionPolicyId :: Parser (TransactionCmds era)
Expand Down
Loading

0 comments on commit ef697f8

Please sign in to comment.