Skip to content

Commit

Permalink
Query for stakepools in runTxBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Sep 5, 2021
1 parent beba405 commit 03339e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
8 changes: 1 addition & 7 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,6 @@ printUtxo shelleyBasedEra' txInOutTuple =
printableValue (TxOutValue _ val) = renderValue val
printableValue (TxOutAdaOnly _ (Lovelace i)) = Text.pack $ show i

joinEither :: (x -> z) -> (y -> z) -> Either x (Either y a) -> Either z a
joinEither f g = join . bimap f (first g)

joinEitherM :: Functor m => (x -> z) -> (y -> z) -> m (Either x (Either y a)) -> m (Either z a)
joinEitherM f g = fmap (joinEither f g)

runQueryStakePools
:: AnyConsensusModeParams
-> NetworkId
Expand All @@ -683,7 +677,7 @@ runQueryStakePools (AnyConsensusModeParams cModeParams)

let localNodeConnInfo = LocalNodeConnectInfo cModeParams network sockPath

result <- ExceptT . joinEitherM ShelleyQueryCmdAcquireFailure id $
result <- ExceptT . fmap (join . first ShelleyQueryCmdAcquireFailure) $
executeLocalStateQueryExpr localNodeConnInfo Nothing $ \_ntcVersion -> runExceptT @ShelleyQueryCmdError $ do
anyE@(AnyCardanoEra era) <- case consensusModeOnly cModeParams of
ByronMode -> return $ AnyCardanoEra ByronEra
Expand Down
17 changes: 7 additions & 10 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,6 @@ runTxBuildRaw (AnyCardanoEra era)
firstExceptT ShelleyTxCmdWriteFileError . newExceptT $
writeFileTextEnvelope fpath Nothing txBody

joinEither :: (x -> z) -> (y -> z) -> Either x (Either y a) -> Either z a
joinEither f g = join . bimap f (first g)

joinEitherM :: Functor m => (x -> z) -> (y -> z) -> m (Either x (Either y a)) -> m (Either z a)
joinEitherM f g = fmap (joinEither f g)

runTxBuild
:: AnyCardanoEra
-> AnyConsensusModeParams
Expand Down Expand Up @@ -446,8 +440,8 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
left (ShelleyTxCmdEraConsensusModeMismatchTxBalance outBody
(AnyConsensusMode CardanoMode) (AnyCardanoEra era))

(utxo, pparams, eraHistory, systemStart) <-
newExceptT . joinEitherM ShelleyTxCmdAcquireFailure id $
(utxo, pparams, eraHistory, systemStart, stakePools) <-
newExceptT . fmap (join . first ShelleyTxCmdAcquireFailure) $
executeLocalStateQueryExpr localNodeConnInfo Nothing $ \_ntcVersion -> runExceptT $ do
utxo <- firstExceptT ShelleyTxCmdTxSubmitErrorEraMismatch . newExceptT . queryExpr
$ QueryInEra eInMode $ QueryInShelleyBasedEra sbe
Expand All @@ -460,7 +454,10 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS

systemStart <- lift $ queryExpr QuerySystemStart

return (utxo, pparams, eraHistory, systemStart)
stakePools <- firstExceptT ShelleyTxCmdTxSubmitErrorEraMismatch . ExceptT $
queryExpr . QueryInEra eInMode . QueryInShelleyBasedEra sbe $ QueryStakePools

return (utxo, pparams, eraHistory, systemStart, stakePools)

let cAddr = case anyAddressInEra era changeAddr of
Just addr -> addr
Expand All @@ -470,7 +467,7 @@ runTxBuild (AnyCardanoEra era) (AnyConsensusModeParams cModeParams) networkId mS
firstExceptT ShelleyTxCmdBalanceTxBody
. hoistEither
$ makeTransactionBodyAutoBalance eInMode systemStart eraHistory
pparams Set.empty utxo txBodyContent
pparams stakePools utxo txBodyContent
cAddr mOverrideWits

putStrLn $ "Estimated transaction fee: " <> (show fee :: String)
Expand Down

0 comments on commit 03339e7

Please sign in to comment.