Skip to content

Commit

Permalink
Remove Render module
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 22, 2022
1 parent 2ebf82e commit 862cbd2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
1 change: 0 additions & 1 deletion cardano-api/cardano-api.cabal
Expand Up @@ -51,7 +51,6 @@ library
other-modules:
-- Splitting up the big Typed module:
Cardano.Api.Address
Cardano.Api.Alonzo.Render
Cardano.Api.Block
Cardano.Api.Certificate
Cardano.Api.Eras
Expand Down
21 changes: 0 additions & 21 deletions cardano-api/src/Cardano/Api/Alonzo/Render.hs

This file was deleted.

32 changes: 24 additions & 8 deletions cardano-api/src/Cardano/Api/Orphans.hs
Expand Up @@ -81,7 +81,6 @@ import Ouroboros.Network.Point (WithOrigin, withOriginToMaybe)
import Prelude hiding ((.), map, show)

import qualified Cardano.Api.Address as Api
import qualified Cardano.Api.Alonzo.Render as Render
import qualified Cardano.Api.Certificate as Api
import qualified Cardano.Api.Ledger.Mary as Api
import qualified Cardano.Api.Script as Api
Expand Down Expand Up @@ -110,6 +109,7 @@ import qualified Cardano.Ledger.Era as Ledger
import qualified Cardano.Ledger.Hashes as Ledger
import qualified Cardano.Ledger.Mary.Value as Mary
import qualified Cardano.Ledger.PoolDistr as Ledger
import qualified Cardano.Ledger.SafeHash as Ledger
import qualified Cardano.Ledger.SafeHash as SafeHash
import qualified Cardano.Ledger.Shelley.API as Shelley
import qualified Cardano.Ledger.Shelley.Constraints as Shelley
Expand All @@ -120,6 +120,7 @@ import qualified Cardano.Ledger.Shelley.Rewards as Shelley
import qualified Cardano.Ledger.Shelley.RewardUpdate as Shelley
import qualified Cardano.Ledger.ShelleyMA.Rules.Utxo as MA
import qualified Cardano.Ledger.ShelleyMA.Timelocks as MA
import qualified Cardano.Ledger.TxIn as Ledger
import qualified Cardano.Prelude as CP
import qualified Cardano.Protocol.TPraos.BHeader as Protocol
import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -747,7 +748,7 @@ instance
toJSON (BadInputsUTxO badInputs) = object
[ "kind" .= String "BadInputsUTxO"
, "badInputs" .= do badInputs :: Set (TxIn (Ledger.Crypto era))
, "error" .= Render.renderBadInputsUTxOErr badInputs
, "error" .= renderBadInputsUTxOErr badInputs
]
toJSON (ExpiredUTxO ttl slot) = object
[ "kind" .= String "ExpiredUTxO"
Expand Down Expand Up @@ -782,7 +783,7 @@ instance
[ "kind" .= String "ValueNotConservedUTxO"
, "consumed" .= do consumed :: Ledger.Value era
, "produced" .= do produced :: Ledger.Value era
, "error" .= Render.renderValueNotConservedErr consumed produced
, "error" .= renderValueNotConservedErr consumed produced
]
toJSON (UpdateFailure f) = object
[ "kind" .= String "UpdateFailure"
Expand Down Expand Up @@ -814,7 +815,7 @@ instance ( ShelleyBasedEra era
toJSON (MA.BadInputsUTxO badInputs) = object
[ "kind" .= String "BadInputsUTxO"
, "badInputs" .= do badInputs :: Set (TxIn (Ledger.Crypto era))
, "error" .= do Render.renderBadInputsUTxOErr badInputs :: Value
, "error" .= do renderBadInputsUTxOErr badInputs :: Value
]
toJSON (MA.OutsideValidityIntervalUTxO validityInterval slot) = object
[ "kind" .= String "ExpiredUTxO"
Expand All @@ -838,7 +839,7 @@ instance ( ShelleyBasedEra era
[ "kind" .= String "ValueNotConservedUTxO"
, "consumed" .= do consumed :: Ledger.Value era
, "produced" .= do produced :: Ledger.Value era
, "error" .= do Render.renderValueNotConservedErr consumed produced :: Value
, "error" .= do renderValueNotConservedErr consumed produced :: Value
]
toJSON (MA.WrongNetwork network addrs) = object
[ "kind" .= String "WrongNetwork"
Expand Down Expand Up @@ -1253,7 +1254,7 @@ instance ToJSON (Alonzo.UtxoPredicateFailure (Alonzo.AlonzoEra StandardCrypto))
toJSON (Alonzo.BadInputsUTxO badInputs) = object
[ "kind" .= String "BadInputsUTxO"
, "badInputs" .= do badInputs :: Set (TxIn (Ledger.Crypto (Consensus.AlonzoEra StandardCrypto)))
, "error" .= do Render.renderBadInputsUTxOErr badInputs :: Value
, "error" .= do renderBadInputsUTxOErr badInputs :: Value
]
toJSON (Alonzo.OutsideValidityIntervalUTxO validtyInterval slot) = object
[ "kind" .= String "ExpiredUTxO"
Expand All @@ -1277,7 +1278,7 @@ instance ToJSON (Alonzo.UtxoPredicateFailure (Alonzo.AlonzoEra StandardCrypto))
[ "kind" .= String "ValueNotConservedUTxO"
, "consumed" .= do consumed :: Mary.Value StandardCrypto
, "produced" .= do produced :: Mary.Value StandardCrypto
, "error" .= do Render.renderValueNotConservedErr consumed produced :: Value
, "error" .= do renderValueNotConservedErr consumed produced :: Value
]
toJSON (Alonzo.WrongNetwork network addrs) = object
[ "kind" .= String "WrongNetwork"
Expand Down Expand Up @@ -1815,4 +1816,19 @@ instance ToJSON Alonzo.TagMismatchDescription where
toJSON = tagMismatchDescriptionToJson

renderTxId :: SupportsMempool.TxId (GenTx (ShelleyBlock era)) -> Text
renderTxId = show
renderTxId (ShelleyTxId shelleyTxId) =
Text.decodeLatin1
. B16.encode
. Crypto.hashToBytes
. Ledger.extractHash
. Ledger._unTxId
$ shelleyTxId

renderBadInputsUTxOErr :: Set (TxIn era) -> Value
renderBadInputsUTxOErr txIns
| Set.null txIns = String "The transaction contains no inputs."
| otherwise = String "The transaction contains inputs that do not exist in the UTxO set."

renderValueNotConservedErr :: Show val => val -> val -> Value
renderValueNotConservedErr consumed produced = String $
"This transaction consumed " <> show consumed <> " but produced " <> show produced

0 comments on commit 862cbd2

Please sign in to comment.