Skip to content

Commit

Permalink
Fix datum inline decoding failure
Browse files Browse the repository at this point in the history
  • Loading branch information
amirmrad authored and j-mueller committed Jan 21, 2025
1 parent dbff9d5 commit 525fbf9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/blockfrost/lib/Convex/Blockfrost/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import Cardano.Api.SerialiseBech32 (SerialiseAsBech32 (..))
import Cardano.Api.SerialiseUsing (UsingRawBytesHex (..))
import Cardano.Api.Shelley (Lovelace)
import Cardano.Api.Shelley qualified as C
import Cardano.Binary (DecoderError)
import Cardano.Binary (DecoderError (DecoderErrorCustom))
import Cardano.Ledger.Alonzo.PParams qualified as L
import Cardano.Ledger.Babbage.PParams qualified as L
import Cardano.Ledger.BaseTypes qualified as BaseTypes
Expand Down Expand Up @@ -272,7 +272,8 @@ toScriptHash = textToIsString

toDatum :: InlineDatum -> Either DecoderError C.HashableScriptData
toDatum (InlineDatum (ScriptDatumCBOR text)) =
C.deserialiseFromCBOR (C.proxyToAsType Proxy) (Text.Encoding.encodeUtf8 text)
either (Left . DecoderErrorCustom "" . Text.pack) pure (Base16.decode $ Text.Encoding.encodeUtf8 text)
>>= C.deserialiseFromCBOR (C.proxyToAsType Proxy)

{- | A @cardano-api@ tx output with a reference script that we only know
the hash of.
Expand Down Expand Up @@ -349,8 +350,9 @@ convertOutput addr_ amount dataHash inlineDatum refScriptHash =
C.TxOutValueShelleyBased
C.shelleyBasedEra
(C.toLedgerValue @era C.maryBasedEra $ foldMap (L.fromList . return . toAssetId) amount)
dat = fmap (C.TxOutDatumInline C.babbageBasedEra) (inlineDatum >>= either (const Nothing) Just . toDatum)
<|> fmap (C.TxOutDatumHash C.alonzoBasedEra . toDatumHash) dataHash
inlinedat = fmap (C.TxOutDatumInline C.babbageBasedEra) (inlineDatum >>= either (const Nothing) Just . toDatum)
datumhash = fmap (C.TxOutDatumHash C.alonzoBasedEra . toDatumHash) dataHash
dat = inlinedat <|> datumhash

txuOutput = C.TxOut addr val (fromMaybe C.TxOutDatumNone dat) C.ReferenceScriptNone
in case refScriptHash of
Expand Down

0 comments on commit 525fbf9

Please sign in to comment.