Skip to content

MempoolUTxOInput parsing fails when Blockfrost API returns inputs without address field #83

@SeungheonOh

Description

@SeungheonOh

Description

The MempoolUTxOInput type requires the address field, but the Blockfrost mempool API sometimes returns inputs without this field, causing JSON parsing to fail.

Error

DecodeFailure "Error in $.inputs[1]: parsing Blockfrost.Types.Cardano.Mempool.MempoolUTxOInput(MempoolUTxOInput) failed, key \"address\" not found"

Full API Response

Click to expand JSON response
{
  "tx": {
    "hash": "30a0535caac8b4f141338dc6e22f7c8b35564097b8970eb5d8d1139cd7d1ef38",
    "output_amount": [
      { "unit": "lovelace", "quantity": "15501315727" },
      { "unit": "00c2011a54a8c3081c7a831ce30f32929cf84d1b44eeaa979688cee15553444358", "quantity": "2403334433361" },
      { "unit": "042ff801ecc3243398baea8b3834236854dbe9b74f07312572cadcde5553444358", "quantity": "1516186602381" },
      { "unit": "1624172476b3f0d74d44f34fe059f56961300011487efae1360f85725553444358", "quantity": "410481082532" },
      { "unit": "190e857e8101555426bcd7b0517bf720c719e471de8b061a6d652bd65553444358", "quantity": "2386431052792" },
      { "unit": "1a62030be0b0346dbff6ba76c90529b5aa5c26bd829da3379a125c295553444358", "quantity": "128458719622" },
      { "unit": "1b014e5bf22bb9a9b087e8fd627be26e2d5210de0940f93a85f633455553444358", "quantity": "486917411260" },
      { "unit": "2c5b7b064f4265aebdcabd4a8ff4ccad073c3858a3921bb1ff9ecd525553444358", "quantity": "992893531091" },
      { "unit": "31dde3db98ad05feb688d4dbb146b3b6054e1246cbcef98c79b0bf665553444378", "quantity": "995980091652" },
      { "unit": "3db2a957d595e25ee3b48b850114ada0de3dd5844b8addee92418cdc5553444358", "quantity": "1394875275648" },
      { "unit": "4430b2d27e2629293bc98cbc5a3f28fa56154348b30ea97717de6acb5553444358", "quantity": "360535913873" },
      { "unit": "4673433f1c46aeeccf22c4340223473adb74d19979f48b03530a82315553444358", "quantity": "963631207725" },
      { "unit": "67baab6ffe50d6c4d0fcb1b56c1462472d9f7ef65d7e0f2bc2dc958f5553444358", "quantity": "319630400513" },
      { "unit": "714205696502e4ca307c1617422e1a7c6b5f8cdcd84cc9c6cb4edc36", "quantity": "2" },
      { "unit": "738c5518214bee002634893ea5db0bcc5bcaa06c0e929eae39ae35d45553444358", "quantity": "14148120167708" },
      { "unit": "7bbec0b9c9f331497ff46f5b5eefbd417b9014fa1af2ea1f64e94f085553444358", "quantity": "203091856689" },
      { "unit": "82cd19068ab0b1f073dcb1327871c2180a91905db70bfcff9cede7a55553444358", "quantity": "1180768351649" },
      { "unit": "9b849a6550cf05253152f29cd9f78f88988c4230d577c7370a696ef95553444358", "quantity": "3070637554083" },
      { "unit": "a6ca802aef9b2eb84bbda17055cbf425ae6898b39266c61698b70d6d5553444358", "quantity": "709606462985" },
      { "unit": "ab6b868582a830f61402c8147d57d8c47572b97651c8c3f33d9e22325553444358", "quantity": "4913733290" },
      { "unit": "b588a0e5ce50bb877b340a22f459948c8a50a9fb64c0c114c234c3935553444358", "quantity": "12699647765857" },
      { "unit": "bdcdb0d8ea0af0234389ea2abf731ae00d6264305406454bd2e93f055553444358", "quantity": "4812932179734" },
      { "unit": "d66bb4f3459e256d92ff0f92f57031e89570590aca21fd508ec6b9225553444358", "quantity": "1044297273245" },
      { "unit": "e548bceca6e19ab60656e598129e00ba1f43c3f46f890db65ef925365553444358", "quantity": "48201487254" },
      { "unit": "ef7e80a9c5d1f652b027bb139678977ac18cdf6235750215269c27a85553444358", "quantity": "636704262274" }
    ],
    "fees": "481061",
    "deposit": "0",
    "size": 2620,
    "invalid_before": null,
    "invalid_hereafter": null,
    "utxo_count": 7,
    "withdrawal_count": 1,
    "mir_cert_count": 0,
    "delegation_count": 0,
    "stake_cert_count": 0,
    "pool_update_count": 0,
    "pool_retire_count": 0,
    "asset_mint_or_burn_count": 2,
    "redeemer_count": 4,
    "valid_contract": true
  },
  "inputs": [
    {
      "address": "addr_test1wpc5yptfv5pwfj3s0stpws3wrf7xkhuvmnvyejwxed8dcds6rk3dj",
      "tx_hash": "721d388668728a0c7c1882e05687f83c9e7266f761e1ae100e619098bebddc07",
      "output_index": 3,
      "collateral": false,
      "reference": false
    },
    {
      "tx_hash": "9415b91b6654241c6f6043216c0d9e3d63d2114cd07f3af8c99abf06a9086673",
      "output_index": 4,
      "collateral": false,
      "reference": false
    },
    {
      "address": "addr_test1wzvnxhf7gayvu92s90zwlrgfzq5px0my8v37u4ullssx63q0quy5e",
      "tx_hash": "137cee8e0d72efcc1802345b390817f8eb4091fb115bd43055f788a2d28a1a6f",
      "output_index": 0,
      "collateral": false,
      "reference": true
    },
    {
      "address": "addr_test1wzdtnfy6dg2mgjy60kmfmh6vdfhf4xrhlgp2lq39uevkysc663gzt",
      "tx_hash": "52248549703460f1c2538d1ecdb9dbba0749f98983576bcc956f348c246ac4f0",
      "output_index": 0,
      "collateral": false,
      "reference": true
    },
    {
      "address": "addr_test1wzdtnfy6dg2mgjy60kmfmh6vdfhf4xrhlgp2lq39uevkysc663gzt",
      "tx_hash": "52248549703460f1c2538d1ecdb9dbba0749f98983576bcc956f348c246ac4f0",
      "output_index": 1,
      "collateral": false,
      "reference": true
    },
    {
      "address": "addr_test1wzdtnfy6dg2mgjy60kmfmh6vdfhf4xrhlgp2lq39uevkysc663gzt",
      "tx_hash": "52248549703460f1c2538d1ecdb9dbba0749f98983576bcc956f348c246ac4f0",
      "output_index": 2,
      "collateral": false,
      "reference": true
    },
    {
      "address": "addr_test1qqesh8e37pm7jdjsjgjcml876lzena02uuzy48j9n0t5dxcy35e4gqn68h3lgwvfxsqclape2tsy5a42rjchpjnj6xpss0sh82",
      "tx_hash": "214d9ff6c73cb8fb27a9a4b31dbc5ee2774fb6b59194578e426996608fa2a7a3",
      "output_index": 2,
      "collateral": true,
      "reference": false
    }
  ],
  "outputs": [
    {
      "address": "addr_test1vp48x3fcw77tkc2eqj0z4fj0909qznluejrzfxqynwner2qg74wfu",
      "amount": [
        { "unit": "lovelace", "quantity": "1055950" },
        { "unit": "31dde3db98ad05feb688d4dbb146b3b6054e1246cbcef98c79b0bf665553444378", "quantity": "651536447853" }
      ],
      "output_index": 0,
      "data_hash": null,
      "inline_datum": null,
      "collateral": false,
      "reference_script_hash": null
    },
    {
      "address": "addr_test1vz6pl3dra67vk55pz5fglt73mtjk2qglahzkffd8ljlsqngad8lt3",
      "amount": [
        { "unit": "lovelace", "quantity": "1038710" },
        { "unit": "31dde3db98ad05feb688d4dbb146b3b6054e1246cbcef98c79b0bf665553444378", "quantity": "6540192" }
      ],
      "output_index": 1,
      "data_hash": null,
      "inline_datum": null,
      "collateral": false,
      "reference_script_hash": null
    },
    {
      "address": "addr_test1wpc5yptfv5pwfj3s0stpws3wrf7xkhuvmnvyejwxed8dcds6rk3dj",
      "amount": [
        { "unit": "lovelace", "quantity": "1353340" },
        { "unit": "714205696502e4ca307c1617422e1a7c6b5f8cdcd84cc9c6cb4edc36", "quantity": "1" }
      ],
      "output_index": 2,
      "data_hash": null,
      "inline_datum": "9f58203ba63149f892c585817de9e208d2778989065f2bdd2ca3a65f1ba8540ac2670758203be2b8dd872c4920ac9215c73abca665a927baac3fd75813cfae769d34b46d04d87a80ff",
      "collateral": false,
      "reference_script_hash": null
    },
    {
      "address": "addr_test1wpc5yptfv5pwfj3s0stpws3wrf7xkhuvmnvyejwxed8dcds6rk3dj",
      "amount": [
        { "unit": "lovelace", "quantity": "1353340" },
        { "unit": "714205696502e4ca307c1617422e1a7c6b5f8cdcd84cc9c6cb4edc36", "quantity": "1" }
      ],
      "output_index": 3,
      "data_hash": null,
      "inline_datum": "9f58203be2b8dd872c4920ac9215c73abca665a927baac3fd75813cfae769d34b46d0458203d37a501dfc3324e9f4eec5cf0369dca2dfdc898c8710c4e846b80400cbe3beed87a80ff",
      "collateral": false,
      "reference_script_hash": null
    },
    {
      "address": "addr_test1qqesh8e37pm7jdjsjgjcml876lzena02uuzy48j9n0t5dxcy35e4gqn68h3lgwvfxsqclape2tsy5a42rjchpjnj6xpss0sh82",
      "amount": [
        { "unit": "lovelace", "quantity": "15496514387" },
        { "unit": "00c2011a54a8c3081c7a831ce30f32929cf84d1b44eeaa979688cee15553444358", "quantity": "2403334433361" },
        { "unit": "042ff801ecc3243398baea8b3834236854dbe9b74f07312572cadcde5553444358", "quantity": "1516186602381" },
        { "unit": "1624172476b3f0d74d44f34fe059f56961300011487efae1360f85725553444358", "quantity": "410481082532" },
        { "unit": "190e857e8101555426bcd7b0517bf720c719e471de8b061a6d652bd65553444358", "quantity": "2386431052792" },
        { "unit": "1a62030be0b0346dbff6ba76c90529b5aa5c26bd829da3379a125c295553444358", "quantity": "128458719622" },
        { "unit": "1b014e5bf22bb9a9b087e8fd627be26e2d5210de0940f93a85f633455553444358", "quantity": "486917411260" },
        { "unit": "2c5b7b064f4265aebdcabd4a8ff4ccad073c3858a3921bb1ff9ecd525553444358", "quantity": "992893531091" },
        { "unit": "31dde3db98ad05feb688d4dbb146b3b6054e1246cbcef98c79b0bf665553444378", "quantity": "344437103607" },
        { "unit": "3db2a957d595e25ee3b48b850114ada0de3dd5844b8addee92418cdc5553444358", "quantity": "1394875275648" },
        { "unit": "4430b2d27e2629293bc98cbc5a3f28fa56154348b30ea97717de6acb5553444358", "quantity": "360535913873" },
        { "unit": "4673433f1c46aeeccf22c4340223473adb74d19979f48b03530a82315553444358", "quantity": "963631207725" },
        { "unit": "67baab6ffe50d6c4d0fcb1b56c1462472d9f7ef65d7e0f2bc2dc958f5553444358", "quantity": "319630400513" },
        { "unit": "738c5518214bee002634893ea5db0bcc5bcaa06c0e929eae39ae35d45553444358", "quantity": "14148120167708" },
        { "unit": "7bbec0b9c9f331497ff46f5b5eefbd417b9014fa1af2ea1f64e94f085553444358", "quantity": "203091856689" },
        { "unit": "82cd19068ab0b1f073dcb1327871c2180a91905db70bfcff9cede7a55553444358", "quantity": "1180768351649" },
        { "unit": "9b849a6550cf05253152f29cd9f78f88988c4230d577c7370a696ef95553444358", "quantity": "3070637554083" },
        { "unit": "a6ca802aef9b2eb84bbda17055cbf425ae6898b39266c61698b70d6d5553444358", "quantity": "709606462985" },
        { "unit": "ab6b868582a830f61402c8147d57d8c47572b97651c8c3f33d9e22325553444358", "quantity": "4913733290" },
        { "unit": "b588a0e5ce50bb877b340a22f459948c8a50a9fb64c0c114c234c3935553444358", "quantity": "12699647765857" },
        { "unit": "bdcdb0d8ea0af0234389ea2abf731ae00d6264305406454bd2e93f055553444358", "quantity": "4812932179734" },
        { "unit": "d66bb4f3459e256d92ff0f92f57031e89570590aca21fd508ec6b9225553444358", "quantity": "1044297273245" },
        { "unit": "e548bceca6e19ab60656e598129e00ba1f43c3f46f890db65ef925365553444358", "quantity": "48201487254" },
        { "unit": "ef7e80a9c5d1f652b027bb139678977ac18cdf6235750215269c27a85553444358", "quantity": "636704262274" }
      ],
      "output_index": 4,
      "data_hash": null,
      "inline_datum": null,
      "collateral": false,
      "reference_script_hash": null
    }
  ],
  "redeemers": [
    { "tx_index": 0, "purpose": "spend", "unit_mem": "43166", "unit_steps": "16018805" },
    { "tx_index": 0, "purpose": "mint", "unit_mem": "40667", "unit_steps": "15718570" },
    { "tx_index": 1, "purpose": "mint", "unit_mem": "44994", "unit_steps": "16682430" },
    { "tx_index": 0, "purpose": "reward", "unit_mem": "438351", "unit_steps": "227537953" }
  ]
}

Note: The second input (inputs[1]) is missing the address field:

{
  "tx_hash": "9415b91b6654241c6f6043216c0d9e3d63d2114cd07f3af8c99abf06a9086673",
  "output_index": 4,
  "collateral": false,
  "reference": false
}

Suggested Fix

Make _address field optional in MempoolUTxOInput:

data MempoolUTxOInput = MempoolUTxOInput
  { _address :: Maybe Text  -- Changed from Text
  , _txHash :: Text
  , _outputIndex :: Integer
  , _collateral :: Bool
  , _reference :: Bool
  }

This appears to be either a Blockfrost API inconsistency or intentional behavior for UTxOs that haven't been fully indexed yet.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions