Skip to content

Commit

Permalink
Add function that encodes Data as JSON friendlyDatum
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Nov 25, 2024
1 parent 955aefd commit 9b3bdc0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cardano-api/internal/Cardano/Api/ReexposeLedger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module Cardano.Api.ReexposeLedger
, EraGov
, EraTx (witsTxL, bodyTxL)
, Tx
, TxDats (..)
, ppPricesL
, unData
, unRedeemers
Expand Down Expand Up @@ -173,6 +174,7 @@ import Cardano.Ledger.Alonzo.Core (AlonzoEraScript (..), AlonzoEraTxBo
import Cardano.Ledger.Alonzo.Genesis (AlonzoGenesis)
import Cardano.Ledger.Alonzo.Scripts (AlonzoPlutusPurpose (..), CostModels, ExUnits (..),
Prices (..))
import Cardano.Ledger.Alonzo.TxWits (TxDats (..))
import Cardano.Ledger.Api (Constitution (..), GovAction (..), unRedeemers)
import Cardano.Ledger.Api.Tx.Cert (pattern AuthCommitteeHotKeyTxCert,
pattern DelegStakeTxCert, pattern DelegTxCert, pattern GenesisDelegTxCert,
Expand Down
7 changes: 7 additions & 0 deletions cardano-api/internal/Cardano/Api/ScriptData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Cardano.Api.ScriptData
, unsafeHashableScriptData
, ScriptData (..)
, friendlyScript
, friendlyDatum

-- * Validating metadata
, validateScriptData
Expand Down Expand Up @@ -65,6 +66,7 @@ import qualified Cardano.Crypto.Hash.Class as Crypto
import Cardano.Ledger.Allegra.Scripts (showTimelock)
import Cardano.Ledger.Alonzo.Core (AlonzoEraScript (..))
import Cardano.Ledger.Alonzo.Scripts (plutusScriptLanguage)
import qualified Cardano.Ledger.Api as Alonzo
import Cardano.Ledger.Binary.Plain (serializeAsHexText)
import Cardano.Ledger.Core (Era, EraScript (..), Script)
import Cardano.Ledger.Plutus (Language)
Expand Down Expand Up @@ -279,6 +281,11 @@ friendlyScript script = Aeson.Object $
, ("script", Aeson.String $ serializeAsHexText $ plutusBinary plutusScript)
]

-- | Friendly dats JSON
friendlyDatum
:: AlonzoEraOnwardsConstraints era => Alonzo.Data (ShelleyLedgerEra era) -> Aeson.Value
friendlyDatum (Alonzo.Data datum) = Aeson.String (T.pack $ show datum)

-- ----------------------------------------------------------------------------
-- Validate script data
--
Expand Down
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ module Cardano.Api
, ScriptWitnessIndex (..)
, renderScriptWitnessIndex
, collectTxBodyScriptWitnesses
, friendlyDatum
, friendlyScript

-- ** Languages supported in each era
Expand Down

0 comments on commit 9b3bdc0

Please sign in to comment.