blockfrost-api 0.2.0.0 → 0.2.1.0
raw patch · 9 files changed
+165/−43 lines, 9 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Blockfrost.Types.Shared.DatumHash: instance Servant.Docs.Internal.ToCapture (Servant.API.Capture.Capture "script_hash" Blockfrost.Types.Shared.DatumHash.DatumHash)
+ Blockfrost.Types.Cardano.Accounts: AddressAssociated :: Address -> AddressAssociated
+ Blockfrost.Types.Cardano.Accounts: [_addressAssociatedAddress] :: AddressAssociated -> Address
+ Blockfrost.Types.Cardano.Accounts: instance Data.Aeson.Types.FromJSON.FromJSON Blockfrost.Types.Cardano.Accounts.AddressAssociated
+ Blockfrost.Types.Cardano.Accounts: instance Data.Aeson.Types.ToJSON.ToJSON Blockfrost.Types.Cardano.Accounts.AddressAssociated
+ Blockfrost.Types.Cardano.Accounts: instance GHC.Classes.Eq Blockfrost.Types.Cardano.Accounts.AddressAssociated
+ Blockfrost.Types.Cardano.Accounts: instance GHC.Generics.Generic Blockfrost.Types.Cardano.Accounts.AddressAssociated
+ Blockfrost.Types.Cardano.Accounts: instance GHC.Show.Show Blockfrost.Types.Cardano.Accounts.AddressAssociated
+ Blockfrost.Types.Cardano.Accounts: instance Servant.Docs.Internal.ToSample Blockfrost.Types.Cardano.Accounts.AddressAssociated
+ Blockfrost.Types.Cardano.Accounts: newtype AddressAssociated
+ Blockfrost.Types.Cardano.Scripts: instance Servant.Docs.Internal.ToSample Blockfrost.Types.Cardano.Scripts.ScriptCBOR
+ Blockfrost.Types.Cardano.Scripts: instance Servant.Docs.Internal.ToSample Blockfrost.Types.Cardano.Scripts.ScriptDatum
+ Blockfrost.Types.Cardano.Scripts: instance Servant.Docs.Internal.ToSample Blockfrost.Types.Cardano.Scripts.ScriptJSON
+ Blockfrost.Types.Shared.DatumHash: instance Servant.Docs.Internal.ToCapture (Servant.API.Capture.Capture "datum_hash" Blockfrost.Types.Shared.DatumHash.DatumHash)
Files
- CHANGELOG.md +7/−0
- blockfrost-api.cabal +2/−1
- src/Blockfrost/API/Cardano/Accounts.hs +19/−0
- src/Blockfrost/Types/Cardano/Accounts.hs +13/−0
- src/Blockfrost/Types/Cardano/Scripts.hs +24/−1
- src/Blockfrost/Types/Shared/DatumHash.hs +2/−2
- test/APISpec.hs +16/−39
- test/Cardano/Accounts.hs +21/−0
- test/Cardano/Blocks.hs +61/−0
CHANGELOG.md view
@@ -1,3 +1,10 @@+# Version [0.2.1.0](https://github.com/blockfrost/blockfrost-haskell/compare/v0.2.0.0...v0.2.1.0) (2021-11-15)++* Additions+ * `ToSample` instances for `ScriptDatum`, `ScriptJSON`, `ScriptCBOR`+ * `/accounts/{stake_address}/addresses` endpoint+ * `/accounts/{stake_address}/addresses/assets` endpoint+ # Version [0.2.0.0](https://github.com/blockfrost/blockfrost-haskell/compare/v0.1.0.0...v0.2.0.0) (2021-10-29) * Breaking changes
blockfrost-api.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: blockfrost-api-version: 0.2.0.0+version: 0.2.1.0 synopsis: API definitions for blockfrost.io description: Core types and Servant API description homepage: https://github.com/blockfrost/blockfrost-haskell@@ -145,6 +145,7 @@ , Cardano.Accounts , Cardano.Addresses , Cardano.Assets+ , Cardano.Blocks , Cardano.Epochs , Cardano.Ledger , Cardano.Metadata
src/Blockfrost/API/Cardano/Accounts.hs view
@@ -76,4 +76,23 @@ :> Pagination :> Sorting :> Get '[JSON] [AccountMir]+ , _accountAssociatedAddresses+ :: route+ :- Summary "Account associated addresses"+ :> Description "Obtain information about the addresses of a specific account."+ :> Capture "stake_address" Address+ :> "addresses"+ :> Pagination+ :> Sorting+ :> Get '[JSON] [AddressAssociated]+ , _accountAssociatedAssets+ :: route+ :- Summary "Assets associated with the account addresses"+ :> Description "Obtain information about assets associated with addresses of a specific account."+ :> Capture "stake_address" Address+ :> "addresses"+ :> "assets"+ :> Pagination+ :> Sorting+ :> Get '[JSON] [Amount] } deriving (Generic)
src/Blockfrost/Types/Cardano/Accounts.hs view
@@ -9,6 +9,7 @@ , AccountRegistrationAction (..) , AccountWithdrawal (..) , AccountMir (..)+ , AddressAssociated (..) ) where import Blockfrost.Types.Shared@@ -201,4 +202,16 @@ { _accountMirAmount = 1202170 , _accountMirTxHash = "1dd15e0ef6e6a17841cb9541c27724072ce4d4b79b91e58432fbaa32d9572531" }+ ]++-- | Address associated with an account address+newtype AddressAssociated = AddressAssociated {_addressAssociatedAddress :: Address}+ deriving stock (Eq, Show, Generic)+ deriving (FromJSON, ToJSON)+ via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressAssociated", CamelToSnake]] AddressAssociated++instance ToSample AddressAssociated where+ toSamples = pure $ samples+ [ AddressAssociated "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"+ , AddressAssociated "addr1q8j55h253zcvl326sk5qdt2n8z7eghzspe0ekxgncr796s2f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sjmd35m" ]
src/Blockfrost/Types/Cardano/Scripts.hs view
@@ -9,7 +9,7 @@ , ScriptCBOR (..) ) where -import Data.Aeson (Value)+import Data.Aeson (Value, object, (.=)) import Data.Text (Text) import Deriving.Aeson import Servant.Docs (ToSample (..), samples, singleSample)@@ -75,12 +75,35 @@ deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_scriptDatum", CamelToSnake]] ScriptDatum +instance ToSample ScriptDatum where+ toSamples =+ pure+ $ singleSample+ $ ScriptDatum+ $ object [ "int" .= (42 :: Int) ]+ newtype ScriptJSON = ScriptJSON { _scriptJsonJson :: Maybe Value } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_scriptJson", CamelToSnake]] ScriptJSON +instance ToSample ScriptJSON where+ toSamples =+ pure+ $ singleSample+ $ ScriptJSON+ $ pure+ $ object [ "type" .= ("sig" :: String)+ , "keyHash" .= ("8ed9e675aaf99868736c372d5eac9f5b3deae4568f0cde6a7d9e1422" :: String)]+ newtype ScriptCBOR = ScriptCBOR { _scriptCborCbor :: Maybe Text } deriving stock (Show, Eq, Generic) deriving (FromJSON, ToJSON) via CustomJSON '[FieldLabelModifier '[StripPrefix "_scriptCbor", CamelToSnake]] ScriptCBOR++instance ToSample ScriptCBOR where+ toSamples =+ pure+ $ singleSample+ $ ScriptCBOR+ $ pure "4e4d01000033222220051200120011"
@@ -32,5 +32,5 @@ , "923918e403bf43c34b4ef6b48eb2ee04babed17320d8d1b9ff9ad086e86f44ec" ] -instance ToCapture (Capture "script_hash" DatumHash) where- toCapture _ = DocCapture "script_hash" "Hash of the script."+instance ToCapture (Capture "datum_hash" DatumHash) where+ toCapture _ = DocCapture "datum_hash" "Datum hash."
test/APISpec.hs view
@@ -17,16 +17,21 @@ spec_sample :: Spec spec_sample = do+ it "parses urlVersion sample" $ do+ decode urlVersionSample+ `shouldBe`+ Just (URLVersion "https://blockfrost.io/" "0.1.0")++ it "parses health sample" $ do+ decode healthSample+ `shouldBe`+ Just (Healthy True)+ it "parses server time sample" $ do decode serverTimeSample `shouldBe` Just (ServerTime 1603400958.947) - it "parses block sample" $ do- eitherDecode blockSample- `shouldBe`- Right blockExpected- it "parses metrics sample" $ do eitherDecode metricsSample `shouldBe`@@ -37,45 +42,17 @@ `shouldBe` Right metricsEndpointsExpected -serverTimeSample = [r| { "server_time": 1603400958947 } |] -blockSample = [r|+urlVersionSample = [r| {- "time": 1641338934,- "height": 15243593,- "hash": "4ea1ba291e8eef538635a53e59fddba7810d1679631cc3aed7c8e6c4091a516a",- "slot": 412162133,- "epoch": 425,- "epoch_slot": 12,- "slot_leader": "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2qnikdy",- "size": 3,- "tx_count": 1,- "output": "128314491794",- "fees": "592661",- "block_vrf": "vrf_vk1wf2k6lhujezqcfe00l6zetxpnmh9n6mwhpmhm0dvfh3fxgmdnrfqkms8ty",- "previous_block": "43ebccb3ac72c7cebd0d9b755a4b08412c9f5dcb81b8a0ad1e3c197d29d47b05",- "next_block": "8367f026cf4b03e116ff8ee5daf149b55ba5a6ec6dec04803b8dc317721d15fa",- "confirmations": 4698+ "url": "https://blockfrost.io/",+ "version": "0.1.0" } |] -blockExpected = Block- { _blockTime = 1641338934- , _blockHeight = pure 15243593- , _blockHash = "4ea1ba291e8eef538635a53e59fddba7810d1679631cc3aed7c8e6c4091a516a"- , _blockSlot = pure 412162133- , _blockEpoch = pure 425- , _blockEpochSlot = pure 12- , _blockSlotLeader = "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2qnikdy"- , _blockSize = 3- , _blockTxCount = 1- , _blockOutput = pure $ 128314491794- , _blockFees = pure $ 592661- , _blockBlockVrf = pure "vrf_vk1wf2k6lhujezqcfe00l6zetxpnmh9n6mwhpmhm0dvfh3fxgmdnrfqkms8ty"- , _blockPreviousBlock = pure "43ebccb3ac72c7cebd0d9b755a4b08412c9f5dcb81b8a0ad1e3c197d29d47b05"- , _blockNextBlock = pure "8367f026cf4b03e116ff8ee5daf149b55ba5a6ec6dec04803b8dc317721d15fa"- , _blockConfirmations = 4698- }+healthSample = [r| { "is_healthy": true } |]++serverTimeSample = [r| { "server_time": 1603400958947 } |] metricsSample = [r| [
test/Cardano/Accounts.hs view
@@ -52,6 +52,11 @@ `shouldBe` Right accountMirsExpected + it "parses account associated addresses sample" $ do+ eitherDecode accountAssociatedAddressesSample+ `shouldBe`+ Right accountAssociatedAddressesExpected+ accountSample = [r| { "stake_address": "stake1ux3g2c9dx2nhhehyrezyxpkstartcqmu9hk63qgfkccw5rqttygt7",@@ -269,3 +274,19 @@ , _accountMirTxHash = "baaa77b63d4d7d2bb3ab02c9b85978c2092c336dede7f59e31ad65452d510c13" } ]++accountAssociatedAddressesSample = [r|+[+ {+ "address": "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"+ },+ {+ "address": "addr1q8j55h253zcvl326sk5qdt2n8z7eghzspe0ekxgncr796s2f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sjmd35m"+ }+]+|]++accountAssociatedAddressesExpected =+ [ AddressAssociated "addr1qx2kd28nq8ac5prwg32hhvudlwggpgfp8utlyqxu6wqgz62f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sy0f4qd"+ , AddressAssociated "addr1q8j55h253zcvl326sk5qdt2n8z7eghzspe0ekxgncr796s2f79qsdmm5dsknt9ecr5w468r9ey0fxwkdrwh08ly3tu9sjmd35m"+ ]
+ test/Cardano/Blocks.hs view
@@ -0,0 +1,61 @@+{-# LANGUAGE NumericUnderscores #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}++module Cardano.Blocks+ where++import Data.Aeson (decode, eitherDecode, encode)+import Data.Text (Text)+import qualified Money+import Test.Hspec+import Test.Tasty.Hspec+import Text.RawString.QQ++import Blockfrost.Types++spec_blocks :: Spec+spec_blocks = do+ it "parses block sample" $ do+ eitherDecode blockSample+ `shouldBe`+ Right blockExpected++blockSample = [r|+{+ "time": 1641338934,+ "height": 15243593,+ "hash": "4ea1ba291e8eef538635a53e59fddba7810d1679631cc3aed7c8e6c4091a516a",+ "slot": 412162133,+ "epoch": 425,+ "epoch_slot": 12,+ "slot_leader": "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2qnikdy",+ "size": 3,+ "tx_count": 1,+ "output": "128314491794",+ "fees": "592661",+ "block_vrf": "vrf_vk1wf2k6lhujezqcfe00l6zetxpnmh9n6mwhpmhm0dvfh3fxgmdnrfqkms8ty",+ "previous_block": "43ebccb3ac72c7cebd0d9b755a4b08412c9f5dcb81b8a0ad1e3c197d29d47b05",+ "next_block": "8367f026cf4b03e116ff8ee5daf149b55ba5a6ec6dec04803b8dc317721d15fa",+ "confirmations": 4698+}+|]++blockExpected = Block+ { _blockTime = 1641338934+ , _blockHeight = pure 15243593+ , _blockHash = "4ea1ba291e8eef538635a53e59fddba7810d1679631cc3aed7c8e6c4091a516a"+ , _blockSlot = pure 412162133+ , _blockEpoch = pure 425+ , _blockEpochSlot = pure 12+ , _blockSlotLeader = "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2qnikdy"+ , _blockSize = 3+ , _blockTxCount = 1+ , _blockOutput = pure $ 128314491794+ , _blockFees = pure $ 592661+ , _blockBlockVrf = pure "vrf_vk1wf2k6lhujezqcfe00l6zetxpnmh9n6mwhpmhm0dvfh3fxgmdnrfqkms8ty"+ , _blockPreviousBlock = pure "43ebccb3ac72c7cebd0d9b755a4b08412c9f5dcb81b8a0ad1e3c197d29d47b05"+ , _blockNextBlock = pure "8367f026cf4b03e116ff8ee5daf149b55ba5a6ec6dec04803b8dc317721d15fa"+ , _blockConfirmations = 4698+ }