Skip to content

Commit

Permalink
Fix Blockfrost getUtxo to exclude spent outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
errfrom committed Jan 8, 2025
1 parent b02718b commit ed1b028
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Internal/Service/Blockfrost.purs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,15 +1186,24 @@ instance Show BlockfrostUtxosOfTransaction where
instance DecodeAeson BlockfrostUtxosOfTransaction where
decodeAeson = aesonObject \obj -> do
txHash <- getField obj "hash"
getField obj "outputs"
>>= aesonArray (map wrap <<< traverse (decodeUtxoEntry txHash))
outputs <- getField obj "outputs"
aesonArray (map (wrap <<< catMaybes) <<< traverse (decodeUtxoEntry txHash))
outputs
where
decodeUtxoEntry
:: TransactionHash
-> Aeson
-> Either JsonDecodeError BlockfrostUnspentOutput
decodeUtxoEntry txHash utxoAeson =
Tuple <$> decodeTxOref txHash utxoAeson <*> decodeAeson utxoAeson
-> Either JsonDecodeError (Maybe BlockfrostUnspentOutput)
decodeUtxoEntry txHash utxoAeson = do
(consumedByTx :: Maybe String) <- aesonObject
(flip getFieldOptional "consumed_by_tx")
utxoAeson
case consumedByTx of
Nothing ->
Just <$>
(Tuple <$> decodeTxOref txHash utxoAeson <*> decodeAeson utxoAeson)
Just _ ->
pure Nothing

decodeTxOref
:: TransactionHash -> Aeson -> Either JsonDecodeError TransactionInput
Expand Down

0 comments on commit ed1b028

Please sign in to comment.