Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add era-independent "debug transaction view" command #840

Merged
merged 7 commits into from
Jul 18, 2024

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Jul 16, 2024

Changelog

- description: |
    Add era-independent "debug transaction view" command
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - refactoring    # QoL changes
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

How to trust this PR

  • The golden file for transaction view on this Conway transaction, which is visible here didn't change: the Conway fields stayed.
  • Golden files for non-Conway eras for transaction view outputs have changed.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • Self-reviewed the diff

@smelc smelc force-pushed the smelc/add-transaction-view-under-debug branch 2 times, most recently from c461329 to 414388c Compare July 17, 2024 12:03
]
++ ( caseByronToBabbageOrConwaysEraOnwards era $

Check notice

Code scanning / HLint

Redundant $ Note

cardano-cli/src/Cardano/CLI/Json/Friendly.hs:245:62: Suggestion: Redundant $
  
Found:
  caseByronToBabbageOrConwaysEraOnwards era
    $ (\ cOnwards
         -> case txProposalProcedures of
              Nothing -> []
              Just (Featured _ TxProposalProceduresNone) -> []
              Just (Featured _ (TxProposalProcedures lProposals _witnesses))
                -> ["governance actions"
                      .= (friendlyLedgerProposals cOnwards $ toList lProposals)])
  
Perhaps:
  caseByronToBabbageOrConwaysEraOnwards
    era
    (\ cOnwards
       -> case txProposalProcedures of
            Nothing -> []
            Just (Featured _ TxProposalProceduresNone) -> []
            Just (Featured _ (TxProposalProcedures lProposals _witnesses))
              -> ["governance actions"
                    .= (friendlyLedgerProposals cOnwards $ toList lProposals)])
["governance actions" .= (friendlyLedgerProposals cOnwards $ toList lProposals)]
)
)
++ ( caseByronToBabbageOrConwaysEraOnwards era $

Check notice

Code scanning / HLint

Redundant $ Note

cardano-cli/src/Cardano/CLI/Json/Friendly.hs:254:62: Suggestion: Redundant $
  
Found:
  caseByronToBabbageOrConwaysEraOnwards era
    $ (\ cOnwards
         -> case txVotingProcedures of
              Nothing -> []
              Just (Featured _ TxVotingProceduresNone) -> []
              Just (Featured _ (TxVotingProcedures votes _witnesses))
                -> ["voters" .= friendlyVotingProcedures cOnwards votes])
  
Perhaps:
  caseByronToBabbageOrConwaysEraOnwards
    era
    (\ cOnwards
       -> case txVotingProcedures of
            Nothing -> []
            Just (Featured _ TxVotingProceduresNone) -> []
            Just (Featured _ (TxVotingProcedures votes _witnesses))
              -> ["voters" .= friendlyVotingProcedures cOnwards votes])
)
)
++ ( caseByronToBabbageOrConwaysEraOnwards era $
const $

Check notice

Code scanning / HLint

Redundant $ Note

cardano-cli/src/Cardano/CLI/Json/Friendly.hs:264:27: Suggestion: Redundant $
  
Found:
  const
    $ ["currentTreasuryValue"
         .= toJSON (unFeatured <$> txCurrentTreasuryValue)]
  
Perhaps:
  const
    ["currentTreasuryValue"
       .= toJSON (unFeatured <$> txCurrentTreasuryValue)]
["currentTreasuryValue" .= toJSON (unFeatured <$> txCurrentTreasuryValue)]
)
++ ( caseByronToBabbageOrConwaysEraOnwards era $
const $

Check notice

Code scanning / HLint

Redundant $ Note

cardano-cli/src/Cardano/CLI/Json/Friendly.hs:268:27: Suggestion: Redundant $
  
Found:
  const
    $ ["treasuryDonation"
         .= toJSON (unFeatured <$> txTreasuryDonation)]
  
Perhaps:
  const
    ["treasuryDonation" .= toJSON (unFeatured <$> txTreasuryDonation)]
( \sbe -> do
caseShelleyToBabbageOrConwayEraOnwards
(const [])
(\cOnwards -> f cOnwards)

Check warning

Code scanning / HLint

Avoid lambda Warning

cardano-cli/src/Cardano/CLI/Json/Friendly.hs:284:15-39: Warning: Avoid lambda
  
Found:
  (\ cOnwards -> f cOnwards)
  
Perhaps:
  f
@smelc smelc force-pushed the smelc/add-transaction-view-under-debug branch from 317ad96 to 1bdc3df Compare July 17, 2024 12:46
@smelc
Copy link
Contributor Author

smelc commented Jul 17, 2024

cc @mkoura

@smelc smelc marked this pull request as ready for review July 17, 2024 13:38
Copy link
Contributor

@palas palas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a lint

Comment on lines +245 to +271
++ ( caseByronToBabbageOrConwaysEraOnwards
( \cOnwards ->
case txProposalProcedures of
Nothing -> []
Just (Featured _ TxProposalProceduresNone) -> []
Just (Featured _ (TxProposalProcedures lProposals _witnesses)) ->
["governance actions" .= (friendlyLedgerProposals cOnwards $ toList lProposals)]
)
era
)
++ ( caseByronToBabbageOrConwaysEraOnwards
( \cOnwards ->
case txVotingProcedures of
Nothing -> []
Just (Featured _ TxVotingProceduresNone) -> []
Just (Featured _ (TxVotingProcedures votes _witnesses)) ->
["voters" .= friendlyVotingProcedures cOnwards votes]
)
era
)
++ ( caseByronToBabbageOrConwaysEraOnwards
(const ["currentTreasuryValue" .= toJSON (unFeatured <$> txCurrentTreasuryValue)])
era
)
++ ( caseByronToBabbageOrConwaysEraOnwards
(const ["treasuryDonation" .= toJSON (unFeatured <$> txTreasuryDonation)])
era
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
++ ( caseByronToBabbageOrConwaysEraOnwards
( \cOnwards ->
case txProposalProcedures of
Nothing -> []
Just (Featured _ TxProposalProceduresNone) -> []
Just (Featured _ (TxProposalProcedures lProposals _witnesses)) ->
["governance actions" .= (friendlyLedgerProposals cOnwards $ toList lProposals)]
)
era
)
++ ( caseByronToBabbageOrConwaysEraOnwards
( \cOnwards ->
case txVotingProcedures of
Nothing -> []
Just (Featured _ TxVotingProceduresNone) -> []
Just (Featured _ (TxVotingProcedures votes _witnesses)) ->
["voters" .= friendlyVotingProcedures cOnwards votes]
)
era
)
++ ( caseByronToBabbageOrConwaysEraOnwards
(const ["currentTreasuryValue" .= toJSON (unFeatured <$> txCurrentTreasuryValue)])
era
)
++ ( caseByronToBabbageOrConwaysEraOnwards
(const ["treasuryDonation" .= toJSON (unFeatured <$> txTreasuryDonation)])
era
++ ( concat
( caseByronToBabbageOrConwaysEraOnwards
( \cOnwards ->
[ case txProposalProcedures of
Nothing -> []
Just (Featured _ TxProposalProceduresNone) -> []
Just (Featured _ (TxProposalProcedures lProposals _witnesses)) ->
["governance actions" .= (friendlyLedgerProposals cOnwards $ toList lProposals)]
, case txVotingProcedures of
Nothing -> []
Just (Featured _ TxVotingProceduresNone) -> []
Just (Featured _ (TxVotingProcedures votes _witnesses)) ->
["voters" .= friendlyVotingProcedures cOnwards votes]
, ["currentTreasuryValue" .= toJSON (unFeatured <$> txCurrentTreasuryValue)]
, ["treasuryDonation" .= toJSON (unFeatured <$> txTreasuryDonation)]
]
)
era
)

We can factor caseByronToBabbageOrConwaysEraOnwards out by using concat. We could also use concatMap but this way we don't even need the consts. Or we could use catMaybes, that would enforce that it is only one item, but probably much less readable

Copy link
Contributor Author

@smelc smelc Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is easier to understand by not using concat, because it avoids nesting. And so it keeps the "one blob of code <==> one item in the list" structure that the items above have 👍

So I'll pass on this suggestion 👍

@smelc
Copy link
Contributor Author

smelc commented Jul 18, 2024

Maybe @Jimbo4350 you want to have a look before merging

@smelc smelc mentioned this pull request Jul 18, 2024
2 tasks
Comment on lines +279 to +283
caseByronToBabbageOrConwaysEraOnwards :: (ConwayEraOnwards era -> [a]) -> CardanoEra era -> [a]
caseByronToBabbageOrConwaysEraOnwards f =
caseByronOrShelleyBasedEra
[]
(caseShelleyToBabbageOrConwayEraOnwards (const []) f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's doing the same same as

monoidForEraInEonA
  :: ()
  => Eon eon
  => Applicative f
  => Monoid a
  => CardanoEra era
  -> (eon era -> f a)
  -> f a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, because Aeson.Value is not a monoid 🙂 (besides, I'm not sure the added abstraction would be worth the harder-to-understand code).

Comment on lines 24 to 27
renderDebugCmdError :: DebugCmdError -> Doc ann
renderDebugCmdError DebugCmdFailed = "Debug command failed"
renderDebugCmdError = \case
DebugCmdFailed -> "Debug command failed"
DebugTxCmdError err -> renderTxCmdError err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an Error instance in the DebugCmdError type module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, changed 👍

@@ -30,60 +19,6 @@ goldenDir, inputDir :: FilePath
goldenDir = "test/cardano-cli-golden/files/golden"
inputDir = "test/cardano-cli-golden/files/input"

-- TODO: Expose command to view byron tx files
_hprop_golden_view_byron_yaml :: Property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes HLINT pragma unneccessary. Can you remove it if it's possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed, changing 👍

@smelc smelc force-pushed the smelc/add-transaction-view-under-debug branch from 1bdc3df to e80203b Compare July 18, 2024 14:08
@smelc smelc enabled auto-merge July 18, 2024 14:22
@smelc smelc disabled auto-merge July 18, 2024 15:04
@smelc smelc merged commit 4d3dbdb into main Jul 18, 2024
22 of 23 checks passed
@smelc smelc deleted the smelc/add-transaction-view-under-debug branch July 18, 2024 15:04
InAnyShelleyBasedEra era txbody <- pure $ unIncompleteCddlTxBody unwitnessed
-- Why are we differentiating between a transaction body and a transaction?
-- In the case of a transaction body, we /could/ simply call @makeSignedTransaction []@
-- to get a transaction which would allow us to reuse friendlyTxBS. However,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something the new api would fix because by default we would either produce an unsigned tx or a signed tx. No need to think about transaction bodies that are missing witnesses.

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

connect to a local node and log the epoch state to a
file. The log file format is line delimited JSON. The
command will not terminate.
transaction Transaction commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transaction debugging commands?

@@ -74,6 +76,11 @@ import GHC.Unicode (isAlphaNum)

data FriendlyFormat = FriendlyJson | FriendlyYaml

viewOutputFormatToFriendlyFormat :: ViewOutputFormat -> FriendlyFormat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think FriendlyFormat is necessary. Why not propagate ViewOutputFormat to the friendly* functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

babbage transaction view on Babbage-era transaction shows some Conway era fields
4 participants