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

Introduce new cardano-cli latest transaction build-estimate command #728

Merged
merged 6 commits into from
Apr 26, 2024

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Apr 18, 2024

Changelog

- description: |
    Introduce new `cardano-cli latest transaction build-estimate` command which will 
    produce a balanced transaction body without requiring a connection to a live node

  type:
  - feature  

Context

Additional context for the PR goes here. If the PR fixes a particular issue please provide a link to the issue.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@Jimbo4350
Copy link
Contributor Author

Jimbo4350 commented Apr 18, 2024

cardano-cli latest transaction build-estimate                                                                 
Usage: cardano-cli latest transaction build-estimate 
                                                       [ --script-valid
                                                       | --script-invalid
                                                       ]
                                                       --shelley-key-witnesses INT
                                                       [--byron-key-witnesses Int]
                                                       --protocol-params-file FILE
                                                       --total-utxo-value VALUE
                                                       (--tx-in TX-IN
                                                         [ --spending-tx-in-reference TX-IN
                                                           ( --spending-plutus-script-v2
                                                           | --spending-plutus-script-v3
                                                           )
                                                           ( --spending-reference-tx-in-datum-cbor-file CBOR FILE
                                                           | --spending-reference-tx-in-datum-file JSON FILE
                                                           | --spending-reference-tx-in-datum-value JSON VALUE
                                                           | --spending-reference-tx-in-inline-datum-present
                                                           )
                                                           ( --spending-reference-tx-in-redeemer-cbor-file CBOR FILE
                                                           | --spending-reference-tx-in-redeemer-file JSON FILE
                                                           | --spending-reference-tx-in-redeemer-value JSON VALUE
                                                           )
                                                           --spending-reference-tx-in-execution-units (INT, INT)
                                                         | --simple-script-tx-in-reference TX-IN
                                                         | --tx-in-script-file FILE
                                                           [
                                                             ( --tx-in-datum-cbor-file CBOR FILE
                                                             | --tx-in-datum-file JSON FILE
                                                             | --tx-in-datum-value JSON VALUE
                                                             | --tx-in-inline-datum-present
                                                             )
                                                             ( --tx-in-redeemer-cbor-file CBOR FILE
                                                             | --tx-in-redeemer-file JSON FILE
                                                             | --tx-in-redeemer-value JSON VALUE
                                                             )
                                                             --tx-in-execution-units (INT, INT)]
                                                         ])
                                                       [--read-only-tx-in-reference TX-IN]
                                                       [ --required-signer FILE
                                                       | --required-signer-hash HASH
                                                       ]
                                                       [--tx-in-collateral TX-IN]
                                                       [--tx-out-return-collateral ADDRESS VALUE]
                                                       [--tx-out ADDRESS VALUE
                                                         [ --tx-out-datum-hash HASH
                                                         | --tx-out-datum-hash-cbor-file CBOR FILE
                                                         | --tx-out-datum-hash-file JSON FILE
                                                         | --tx-out-datum-hash-value JSON VALUE
                                                         | --tx-out-datum-embed-cbor-file CBOR FILE
                                                         | --tx-out-datum-embed-file JSON FILE
                                                         | --tx-out-datum-embed-value JSON VALUE
                                                         | --tx-out-inline-datum-cbor-file CBOR FILE
                                                         | --tx-out-inline-datum-file JSON FILE
                                                         | --tx-out-inline-datum-value JSON VALUE
                                                         ]
                                                         [--tx-out-reference-script-file FILE]]
                                                       --change-address ADDRESS
                                                       [--mint VALUE
                                                         ( --mint-script-file FILE
                                                           [
                                                             ( --mint-redeemer-cbor-file CBOR FILE
                                                             | --mint-redeemer-file JSON FILE
                                                             | --mint-redeemer-value JSON VALUE
                                                             )
                                                             --mint-execution-units (INT, INT)]
                                                         | --simple-minting-script-tx-in-reference TX-IN
                                                           --policy-id HASH
                                                         | --mint-tx-in-reference TX-IN
                                                           ( --mint-plutus-script-v2
                                                           | --mint-plutus-script-v3
                                                           )
                                                           ( --mint-reference-tx-in-redeemer-cbor-file CBOR FILE
                                                           | --mint-reference-tx-in-redeemer-file JSON FILE
                                                           | --mint-reference-tx-in-redeemer-value JSON VALUE
                                                           )
                                                           --mint-reference-tx-in-execution-units (INT, INT)
                                                           --policy-id HASH
                                                         )]
                                                       [--invalid-before SLOT]
                                                       [--invalid-hereafter SLOT]
                                                       [--certificate-file FILE
                                                         [ --certificate-script-file FILE
                                                           [
                                                             ( --certificate-redeemer-cbor-file CBOR FILE
                                                             | --certificate-redeemer-file JSON FILE
                                                             | --certificate-redeemer-value JSON VALUE
                                                             )
                                                             --certificate-execution-units (INT, INT)]
                                                         | --certificate-tx-in-reference TX-IN
                                                           ( --certificate-plutus-script-v2
                                                           | --certificate-plutus-script-v3
                                                           )
                                                           ( --certificate-reference-tx-in-redeemer-cbor-file CBOR FILE
                                                           | --certificate-reference-tx-in-redeemer-file JSON FILE
                                                           | --certificate-reference-tx-in-redeemer-value JSON VALUE
                                                           )
                                                           --certificate-reference-tx-in-execution-units (INT, INT)
                                                         ]]
                                                       [--withdrawal WITHDRAWAL
                                                         [ --withdrawal-script-file FILE
                                                           [
                                                             ( --withdrawal-redeemer-cbor-file CBOR FILE
                                                             | --withdrawal-redeemer-file JSON FILE
                                                             | --withdrawal-redeemer-value JSON VALUE
                                                             )
                                                             --withdrawal-execution-units (INT, INT)]
                                                         | --withdrawal-tx-in-reference TX-IN
                                                           ( --withdrawal-plutus-script-v2
                                                           | --withdrawal-plutus-script-v3
                                                           )
                                                           ( --withdrawal-reference-tx-in-redeemer-cbor-file CBOR FILE
                                                           | --withdrawal-reference-tx-in-redeemer-file JSON FILE
                                                           | --withdrawal-reference-tx-in-redeemer-value JSON VALUE
                                                           )
                                                           --withdrawal-reference-tx-in-execution-units (INT, INT)
                                                         ]]
                                                       [--tx-total-collateral INTEGER]
                                                       [--reference-script-size NATURAL]
                                                       [ --json-metadata-no-schema
                                                       | --json-metadata-detailed-schema
                                                       ]
                                                       [--auxiliary-script-file FILE]
                                                       [ --metadata-json-file FILE
                                                       | --metadata-cbor-file FILE
                                                       ]
                                                       [--update-proposal-file FILE]
                                                       --out-file FILE

  Build a balanced transaction without access to a live node (automatically estimates fees)

@Jimbo4350 Jimbo4350 force-pushed the jordan/add-build-cmd-estimate branch from c399f5f to bcd5053 Compare April 18, 2024 18:15

{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🥲

              ┃   │ ━━━━ stderr ━━━━
                ┃   │ 
                ┃   │ cardano-cli: user error (Pattern match failure in 'do' block at src/Cardano/CLI/EraBased/Run/Transaction.hs:787:3-26)

Copy link
Contributor

Choose a reason for hiding this comment

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

But there's no pattern matching in that fragment:

  validatedTxCerts
     <- hoistEither
          . first TxCmdTxCertificatesValidationError
          $ validateTxCertificates era certsAndMaybeScriptWits

strange

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated it.

@Jimbo4350 Jimbo4350 force-pushed the jordan/add-build-cmd-estimate branch 3 times, most recently from 085c1e5 to 7c3e048 Compare April 25, 2024 19:48
@Jimbo4350 Jimbo4350 force-pushed the jordan/add-build-cmd-estimate branch from 7c3e048 to b43bdbe Compare April 26, 2024 16:29
@Jimbo4350 Jimbo4350 enabled auto-merge April 26, 2024 16:29
poolsToDeregister = Set.fromList $ catMaybes [getPoolDeregistrationInfo cert | (cert,_) <- certsAndMaybeScriptWits]
totCol = fromMaybe 0 plutusCollateral
pScriptExecUnits = Map.fromList [ (sWitIndex, execUnits)
| (sWitIndex, (AnyScriptWitness (PlutusScriptWitness _ _ _ _ _ execUnits))) <- collectTxBodyScriptWitnesses sbe txBodyContent

Check notice

Code scanning / HLint

Redundant bracket Note

cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs:362:53-112: Suggestion: Redundant bracket
  
Found:
  (sWitIndex,
   (AnyScriptWitness (PlutusScriptWitness _ _ _ _ _ execUnits)))
  
Perhaps:
  (sWitIndex,
   AnyScriptWitness (PlutusScriptWitness _ _ _ _ _ execUnits))
estimateBalancedTxBody eon txBodyContent (unLedgerProtocolParameters ledgerPParams) poolsToDeregister
stakeCredentialsToDeregisterMap drepsToDeregisterMap
pScriptExecUnits totCol shelleyWitnesses (fromMaybe 0 mByronWitnesses)
(fromMaybe 0 (unReferenceScriptSize <$> totalReferenceScriptSize)) (anyAddressInShelleyBasedEra sbe changeAddr)

Check warning

Code scanning / HLint

Use maybe Warning

cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs:370:31-94: Warning: Use maybe
  
Found:
  fromMaybe 0 (unReferenceScriptSize <$> totalReferenceScriptSize)
  
Perhaps:
  maybe 0 unReferenceScriptSize totalReferenceScriptSize
@Jimbo4350 Jimbo4350 added this pull request to the merge queue Apr 26, 2024
Merged via the queue into main with commit d63cfe5 Apr 26, 2024
21 checks passed
@Jimbo4350 Jimbo4350 deleted the jordan/add-build-cmd-estimate branch April 26, 2024 16:53
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.

2 participants