Skip to content

Commit

Permalink
Merge pull request #38 from sourabhxyz/add-address-in-response
Browse files Browse the repository at this point in the history
Added address in UTxO response - useful when querying by payment credential
  • Loading branch information
sorki committed Sep 18, 2023
2 parents 9bfcc21 + d1ace8d commit 12bc082
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
22 changes: 13 additions & 9 deletions blockfrost-api/src/Blockfrost/Types/Cardano/Addresses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ instance ToSample AddressDetails where

-- | UTxOs of the address
data AddressUtxo = AddressUtxo
{ _addressUtxoTxHash :: TxHash -- ^ Transaction hash of the UTXO
, _addressUtxoOutputIndex :: Integer -- ^ UTXO index in the transaction
, _addressUtxoAmount :: [Amount] -- ^ Amounts of Lovelaces or tokens
, _addressUtxoBlock :: BlockHash -- ^ Block hash of the UTXO
, _addressUtxoDataHash :: Maybe DatumHash -- ^ The hash of the transaction output datum
, _addressUtxoInlineDatum :: Maybe InlineDatum -- ^ CBOR encoded inline datum
{ _addressUtxoAddress :: Address -- ^ Address in the UTxO. Useful when querying by payment credential.
, _addressUtxoTxHash :: TxHash -- ^ Transaction hash of the UTXO
, _addressUtxoOutputIndex :: Integer -- ^ UTXO index in the transaction
, _addressUtxoAmount :: [Amount] -- ^ Amounts of Lovelaces or tokens
, _addressUtxoBlock :: BlockHash -- ^ Block hash of the UTXO
, _addressUtxoDataHash :: Maybe DatumHash -- ^ The hash of the transaction output datum
, _addressUtxoInlineDatum :: Maybe InlineDatum -- ^ CBOR encoded inline datum
, _addressUtxoReferenceScriptHash :: Maybe ScriptHash -- ^ The hash of the reference script of the output
} deriving stock (Show, Eq, Generic)
deriving (FromJSON, ToJSON)
Expand All @@ -95,7 +96,8 @@ data AddressUtxo = AddressUtxo
instance ToSample AddressUtxo where
toSamples = pure $ samples
[ AddressUtxo
{ _addressUtxoTxHash = "39a7a284c2a0948189dc45dec670211cd4d72f7b66c5726c08d9b3df11e44d58"
{ _addressUtxoAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressUtxoTxHash = "39a7a284c2a0948189dc45dec670211cd4d72f7b66c5726c08d9b3df11e44d58"
, _addressUtxoOutputIndex = 0
, _addressUtxoAmount = [ AdaAmount 42000000 ]
, _addressUtxoBlock = "7eb8e27d18686c7db9a18f8bbcfe34e3fed6e047afaa2d969904d15e934847e6"
Expand All @@ -104,7 +106,8 @@ instance ToSample AddressUtxo where
, _addressUtxoReferenceScriptHash = Nothing
}
, AddressUtxo
{ _addressUtxoTxHash = "4c4e67bafa15e742c13c592b65c8f74c769cd7d9af04c848099672d1ba391b49"
{ _addressUtxoAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressUtxoTxHash = "4c4e67bafa15e742c13c592b65c8f74c769cd7d9af04c848099672d1ba391b49"
, _addressUtxoOutputIndex = 0
, _addressUtxoAmount = [ AdaAmount 729235000 ]
, _addressUtxoBlock = "953f1b80eb7c11a7ffcd67cbd4fde66e824a451aca5a4065725e5174b81685b7"
Expand All @@ -113,7 +116,8 @@ instance ToSample AddressUtxo where
, _addressUtxoReferenceScriptHash = Nothing
}
, AddressUtxo
{ _addressUtxoTxHash = "768c63e27a1c816a83dc7b07e78af673b2400de8849ea7e7b734ae1333d100d2"
{ _addressUtxoAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressUtxoTxHash = "768c63e27a1c816a83dc7b07e78af673b2400de8849ea7e7b734ae1333d100d2"
, _addressUtxoOutputIndex = 1
, _addressUtxoAmount =
[ AdaAmount 42000000
Expand Down
12 changes: 9 additions & 3 deletions blockfrost-api/test/Cardano/Addresses.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ addressDetailsExpected =
addressUtxosSample = [r|
[
{
"address": "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
"tx_hash": "39a7a284c2a0948189dc45dec670211cd4d72f7b66c5726c08d9b3df11e44d58",
"output_index": 0,
"amount":
Expand All @@ -139,6 +140,7 @@ addressUtxosSample = [r|
"reference_script_hash": null
},
{
"address": "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
"tx_hash": "4c4e67bafa15e742c13c592b65c8f74c769cd7d9af04c848099672d1ba391b49",
"output_index": 0,
"amount":
Expand All @@ -154,6 +156,7 @@ addressUtxosSample = [r|
"reference_script_hash": null
},
{
"address": "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
"tx_hash": "768c63e27a1c816a83dc7b07e78af673b2400de8849ea7e7b734ae1333d100d2",
"output_index": 1,
"amount":
Expand All @@ -177,7 +180,8 @@ addressUtxosSample = [r|

addressUtxosExpected =
[ AddressUtxo
{ _addressUtxoTxHash = "39a7a284c2a0948189dc45dec670211cd4d72f7b66c5726c08d9b3df11e44d58"
{ _addressUtxoAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressUtxoTxHash = "39a7a284c2a0948189dc45dec670211cd4d72f7b66c5726c08d9b3df11e44d58"
, _addressUtxoOutputIndex = 0
, _addressUtxoAmount = [ AdaAmount 42000000 ]
, _addressUtxoBlock = "7eb8e27d18686c7db9a18f8bbcfe34e3fed6e047afaa2d969904d15e934847e6"
Expand All @@ -186,7 +190,8 @@ addressUtxosExpected =
, _addressUtxoReferenceScriptHash = Nothing
}
, AddressUtxo
{ _addressUtxoTxHash = "4c4e67bafa15e742c13c592b65c8f74c769cd7d9af04c848099672d1ba391b49"
{ _addressUtxoAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressUtxoTxHash = "4c4e67bafa15e742c13c592b65c8f74c769cd7d9af04c848099672d1ba391b49"
, _addressUtxoOutputIndex = 0
, _addressUtxoAmount = [ AdaAmount 729235000 ]
, _addressUtxoBlock = "953f1b80eb7c11a7ffcd67cbd4fde66e824a451aca5a4065725e5174b81685b7"
Expand All @@ -195,7 +200,8 @@ addressUtxosExpected =
, _addressUtxoReferenceScriptHash = Nothing
}
, AddressUtxo
{ _addressUtxoTxHash = "768c63e27a1c816a83dc7b07e78af673b2400de8849ea7e7b734ae1333d100d2"
{ _addressUtxoAddress = "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz"
, _addressUtxoTxHash = "768c63e27a1c816a83dc7b07e78af673b2400de8849ea7e7b734ae1333d100d2"
, _addressUtxoOutputIndex = 1
, _addressUtxoAmount =
[ AdaAmount 42000000
Expand Down

0 comments on commit 12bc082

Please sign in to comment.