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 new field 'inlineDatumRaw' to TxOut ToJSON instance #632

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cardano-api/internal/Cardano/Api/Tx/Body.hs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ import Cardano.Api.ProtocolParameters
import qualified Cardano.Api.ReexposeLedger as Ledger
import Cardano.Api.Script
import Cardano.Api.ScriptData
import Cardano.Api.ScriptData ()
import Cardano.Api.SerialiseCBOR
import Cardano.Api.SerialiseJSON
import Cardano.Api.SerialiseRaw
import Cardano.Api.Tx.Sign
Expand Down Expand Up @@ -266,6 +268,7 @@ import qualified Data.Aeson.Key as Aeson
import qualified Data.Aeson.Types as Aeson
import Data.Bifunctor (Bifunctor (..))
import Data.ByteString (ByteString)
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as BSC
import qualified Data.DList as DList
import Data.Foldable (for_)
Expand All @@ -288,6 +291,7 @@ import qualified Data.Set as Set
import Data.String
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Type.Equality (TestEquality (..), (:~:) (Refl))
import Data.Word (Word16, Word32, Word64)
import GHC.Exts (IsList (..))
Expand Down Expand Up @@ -372,6 +376,7 @@ txOutToJsonValue era (TxOut addr val dat refScript) =
, datHashJsonVal dat
, "datum" .= datJsonVal dat
, "inlineDatum" .= inlineDatumJsonVal dat
, "inlineDatumRaw" .= inlineDatumRawJsonCbor dat
, "referenceScript" .= refScriptJsonVal refScript
]
ConwayEra ->
Expand All @@ -381,6 +386,7 @@ txOutToJsonValue era (TxOut addr val dat refScript) =
, datHashJsonVal dat
, "datum" .= datJsonVal dat
, "inlineDatum" .= inlineDatumJsonVal dat
, "inlineDatumRaw" .= inlineDatumRawJsonCbor dat
, "referenceScript" .= refScriptJsonVal refScript
]
where
Expand Down Expand Up @@ -412,6 +418,19 @@ txOutToJsonValue era (TxOut addr val dat refScript) =
TxOutDatumInTx'{} -> Aeson.Null
TxOutDatumInline _ datum -> scriptDataToJson ScriptDataJsonDetailedSchema datum

inlineDatumRawJsonCbor :: TxOutDatum ctx era -> Aeson.Value
inlineDatumRawJsonCbor d =
case d of
TxOutDatumNone -> Aeson.Null
TxOutDatumHash{} -> Aeson.Null
TxOutDatumInTx'{} -> Aeson.Null
TxOutDatumInline _ datum ->
Aeson.String
. Text.decodeUtf8
. Base16.encode
ffakenz marked this conversation as resolved.
Show resolved Hide resolved
. serialiseToCBOR
$ datum

refScriptJsonVal :: ReferenceScript era -> Aeson.Value
refScriptJsonVal rScript =
case rScript of
Expand Down
Loading