packages feed

blockfrost-api 0.3.0.0 → 0.3.1.0

raw patch · 13 files changed

+92/−12 lines, 13 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Blockfrost.Lens: blockTime :: HasBlockTime s a => Lens' s a
+ Blockfrost.Lens: class HasBlockTime s a | s -> a
+ Blockfrost.Lens: instance Blockfrost.Lens.HasBlockTime Blockfrost.Types.Cardano.Addresses.AddressTransaction Data.Time.Clock.Internal.POSIXTime.POSIXTime
+ Blockfrost.Types.Cardano.Addresses: [_addressTransactionBlockTime] :: AddressTransaction -> POSIXTime
+ Blockfrost.Types.Cardano.Blocks: instance Data.Aeson.Types.FromJSON.FromJSON (Blockfrost.Types.Shared.Address.Address, [Blockfrost.Types.Shared.TxHash.TxHash])
+ Blockfrost.Types.Cardano.Blocks: instance Data.Aeson.Types.ToJSON.ToJSON (Blockfrost.Types.Shared.Address.Address, [Blockfrost.Types.Shared.TxHash.TxHash])
+ Blockfrost.Types.Shared.Address: instance GHC.Classes.Ord Blockfrost.Types.Shared.Address.Address
+ Blockfrost.Types.Shared.AssetId: instance GHC.Classes.Ord Blockfrost.Types.Shared.AssetId.AssetId
+ Blockfrost.Types.Shared.BlockHash: instance GHC.Classes.Ord Blockfrost.Types.Shared.BlockHash.BlockHash
+ Blockfrost.Types.Shared.Epoch: instance GHC.Classes.Ord Blockfrost.Types.Shared.Epoch.Epoch
+ Blockfrost.Types.Shared.Epoch: instance GHC.Enum.Enum Blockfrost.Types.Shared.Epoch.Epoch
+ Blockfrost.Types.Shared.Epoch: instance GHC.Real.Integral Blockfrost.Types.Shared.Epoch.Epoch
+ Blockfrost.Types.Shared.Epoch: instance GHC.Real.Real Blockfrost.Types.Shared.Epoch.Epoch
+ Blockfrost.Types.Shared.Slot: instance GHC.Classes.Ord Blockfrost.Types.Shared.Slot.Slot
+ Blockfrost.Types.Shared.Slot: instance GHC.Enum.Enum Blockfrost.Types.Shared.Slot.Slot
+ Blockfrost.Types.Shared.Slot: instance GHC.Real.Integral Blockfrost.Types.Shared.Slot.Slot
+ Blockfrost.Types.Shared.Slot: instance GHC.Real.Real Blockfrost.Types.Shared.Slot.Slot
+ Blockfrost.Types.Shared.TxHash: instance GHC.Classes.Ord Blockfrost.Types.Shared.TxHash.TxHash
- Blockfrost.Types.Cardano.Addresses: AddressTransaction :: TxHash -> Integer -> Integer -> AddressTransaction
+ Blockfrost.Types.Cardano.Addresses: AddressTransaction :: TxHash -> Integer -> Integer -> POSIXTime -> AddressTransaction

Files

CHANGELOG.md view
@@ -1,3 +1,11 @@+# Version [0.3.1.0](https://github.com/blockfrost/blockfrost-haskell/compare/v0.3.0.0...v0.3.1.0) (2022-02-17)++* Additions+  * `/blocks/${hash_or_number}/addresses` endpoint (Affected addresses in a block)+  * `blockTime` field to `AddressTransaction`+  * `Ord` instances for `Address`, `AssetId`, `BlockHash`, `Epoch`, `Slot`, `TxHash`+  * `Enum`, `Real`, `Integral` for `Slot` and `Epoch`+ # Version [0.3.0.0](https://github.com/blockfrost/blockfrost-haskell/compare/v0.2.1.0...v0.3.0.0) (2022-02-07)  * Changes
blockfrost-api.cabal view
@@ -1,6 +1,6 @@ cabal-version:       2.2 name:                blockfrost-api-version:             0.3.0.0+version:             0.3.1.0 synopsis:            API definitions for blockfrost.io description:         Core types and Servant API description homepage:            https://github.com/blockfrost/blockfrost-haskell
src/Blockfrost/API/Cardano/Blocks.hs view
@@ -79,4 +79,13 @@         :> Pagination         :> Sorting         :> Get '[JSON] [TxHash]+      , _blockAffectedAddresses+        :: route+        :- Summary "Addresses affected in a specific block"+        :> Description "Return list of addresses affected in the specified block with additional information, \+                       \sorted by the bech32 address, ascending."+        :> Capture "hash_or_number" (Either Integer BlockHash)+        :> "addresses"+        :> Pagination+        :> Get '[JSON] [(Address, [TxHash])]     } deriving (Generic)
src/Blockfrost/Types/Cardano/Addresses.hs view
@@ -126,6 +126,7 @@     _addressTransactionTxHash      :: TxHash -- ^ Hash of the transaction   , _addressTransactionTxIndex     :: Integer -- ^ Transaction index within the block   , _addressTransactionBlockHeight :: Integer -- ^ Block height+  , _addressTransactionBlockTime   :: POSIXTime -- ^ Block creation time in UNIX time   } deriving stock (Show, Eq, Generic)   deriving (FromJSON, ToJSON)   via CustomJSON '[FieldLabelModifier '[StripPrefix "_addressTransaction", CamelToSnake]] AddressTransaction@@ -136,15 +137,18 @@       { _addressTransactionTxHash = "8788591983aa73981fc92d6cddbbe643959f5a784e84b8bee0db15823f575a5b"       , _addressTransactionTxIndex = 6       , _addressTransactionBlockHeight = 69+      , _addressTransactionBlockTime = 1635505891       }     , AddressTransaction       { _addressTransactionTxHash = "52e748c4dec58b687b90b0b40d383b9fe1f24c1a833b7395cdf07dd67859f46f"       , _addressTransactionTxIndex = 9       , _addressTransactionBlockHeight = 4547+      , _addressTransactionBlockTime = 1635505987       }     , AddressTransaction       { _addressTransactionTxHash = "e8073fd5318ff43eca18a852527166aa8008bee9ee9e891f585612b7e4ba700b"       , _addressTransactionTxIndex = 0       , _addressTransactionBlockHeight = 564654+      , _addressTransactionBlockTime = 1834505492       }     ]
src/Blockfrost/Types/Cardano/Blocks.hs view
@@ -5,6 +5,9 @@   ) where  import Data.Text (Text)+import Data.Aeson+import Data.Aeson.Types (explicitParseField)+import qualified Data.Vector import Deriving.Aeson import Servant.Docs (ToSample (..), singleSample) @@ -50,3 +53,19 @@     , _blockNextBlock = pure "8367f026cf4b03e116ff8ee5daf149b55ba5a6ec6dec04803b8dc317721d15fa"     , _blockConfirmations = 4698     }++-- instances for getBlockAffectedAddreses response+instance {-# OVERLAPS #-} ToJSON (Address, [TxHash]) where+  toJSON (addr, txs) = object [+        "address" .= toJSON addr+      , "transactions" .= map (\tx -> object [ "tx_hash" .= toJSON tx ]) txs+      ]++instance {-# OVERLAPS #-} FromJSON (Address, [TxHash]) where+  parseJSON = withObject "addrTxs" $ \o -> do+    addr <- o .: "address"+    txs <- explicitParseField+      (withArray "a" $ \a -> mapM (withObject "txHashes" $ \to -> to .: "tx_hash") (Data.Vector.toList a))+      o+      "transactions"+    pure (addr, txs)
src/Blockfrost/Types/Shared/Address.hs view
@@ -12,7 +12,7 @@ import Servant.Docs (DocCapture (..), ToCapture (..), ToSample (..), samples)  newtype Address = Address Text-  deriving stock (Eq, Show, Generic)+  deriving stock (Eq, Ord, Show, Generic)   deriving newtype (FromHttpApiData, ToHttpApiData, FromJSON, ToJSON)  mkAddress :: Text -> Address
src/Blockfrost/Types/Shared/AssetId.hs view
@@ -14,7 +14,7 @@ -- | Concatenation of asset policy ID -- and hex-encoded asset name newtype AssetId = AssetId Text-  deriving stock (Eq, Show, Generic)+  deriving stock (Eq, Ord, Show, Generic)   deriving newtype (FromHttpApiData, ToHttpApiData, FromJSON, ToJSON)  mkAssetId :: Text -> AssetId
src/Blockfrost/Types/Shared/BlockHash.hs view
@@ -14,7 +14,7 @@ import qualified Text.Read  newtype BlockHash = BlockHash Text-  deriving stock (Eq, Show, Generic)+  deriving stock (Eq, Ord, Show, Generic)   deriving newtype (FromHttpApiData, ToHttpApiData, FromJSON, ToJSON)  mkBlockHash :: Text -> BlockHash
src/Blockfrost/Types/Shared/Epoch.hs view
@@ -9,8 +9,8 @@ import Servant.Docs (DocCapture (..), ToCapture (..), ToSample (..), samples)  newtype Epoch = Epoch Integer-  deriving stock (Eq, Show, Generic)-  deriving newtype (Num, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON)+  deriving stock (Eq, Ord, Show, Generic)+  deriving newtype (Num, Enum, Real, Integral, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON)  unEpoch :: Epoch -> Integer unEpoch (Epoch i) = i
src/Blockfrost/Types/Shared/Slot.hs view
@@ -9,8 +9,8 @@ import Servant.Docs (DocCapture (..), ToCapture (..), ToSample (..), samples)  newtype Slot = Slot Integer-  deriving stock (Eq, Show, Generic)-  deriving newtype (Num, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON)+  deriving stock (Eq, Ord, Show, Generic)+  deriving newtype (Num, Enum, Real, Integral, FromHttpApiData, ToHttpApiData, FromJSON, ToJSON)  unSlot :: Slot -> Integer unSlot (Slot i) = i
src/Blockfrost/Types/Shared/TxHash.hs view
@@ -14,7 +14,7 @@  -- | Id (hash) of the transaction newtype TxHash = TxHash { unTxHash :: Text }-  deriving stock (Show, Eq, Generic)+  deriving stock (Show, Eq, Ord, Generic)   deriving newtype (FromHttpApiData, ToHttpApiData)  instance IsString TxHash where
test/Cardano/Addresses.hs view
@@ -205,17 +205,20 @@     {         "tx_hash": "8788591983aa73981fc92d6cddbbe643959f5a784e84b8bee0db15823f575a5b",         "tx_index": 6,-        "block_height": 69+        "block_height": 69,+        "block_time": 1635505891     },     {         "tx_hash": "52e748c4dec58b687b90b0b40d383b9fe1f24c1a833b7395cdf07dd67859f46f",         "tx_index": 9,-        "block_height": 4547+        "block_height": 4547,+        "block_time": 1635505987     },     {         "tx_hash": "e8073fd5318ff43eca18a852527166aa8008bee9ee9e891f585612b7e4ba700b",         "tx_index": 0,-        "block_height": 564654+        "block_height": 564654,+        "block_time": 1834505492     } ] |]@@ -225,15 +228,18 @@     { _addressTransactionTxHash = "8788591983aa73981fc92d6cddbbe643959f5a784e84b8bee0db15823f575a5b"     , _addressTransactionTxIndex = 6     , _addressTransactionBlockHeight = 69+    , _addressTransactionBlockTime = 1635505891     }   , AddressTransaction     { _addressTransactionTxHash = "52e748c4dec58b687b90b0b40d383b9fe1f24c1a833b7395cdf07dd67859f46f"     , _addressTransactionTxIndex = 9     , _addressTransactionBlockHeight = 4547+    , _addressTransactionBlockTime = 1635505987     }   , AddressTransaction     { _addressTransactionTxHash = "e8073fd5318ff43eca18a852527166aa8008bee9ee9e891f585612b7e4ba700b"     , _addressTransactionTxIndex = 0     , _addressTransactionBlockHeight = 564654+    , _addressTransactionBlockTime = 1834505492     }   ]
test/Cardano/Blocks.hs view
@@ -22,6 +22,11 @@     `shouldBe`     Right blockExpected +  it "parses afftected addresses sample" $ do+    eitherDecode affectedAddrsSample+    `shouldBe`+    Right affectedAddrsExpected+ blockSample = [r| {     "time": 1641338934,@@ -59,3 +64,32 @@   , _blockNextBlock = pure "8367f026cf4b03e116ff8ee5daf149b55ba5a6ec6dec04803b8dc317721d15fa"   , _blockConfirmations = 4698   }++affectedAddrsSample = [r|+[+  {+    "address": "addr1q9ld26v2lv8wvrxxmvg90pn8n8n5k6tdst06q2s856rwmvnueldzuuqmnsye359fqrk8hwvenjnqultn7djtrlft7jnq7dy7wv",+    "transactions": [+      {+        "tx_hash": "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dce628516157f0"+      }+    ]+  },+  {+    "address": "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",+    "transactions": [+      {+        "tx_hash": "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dce628516157d0"+      }+    ]+  }+]+|]++affectedAddrsExpected :: [(Address, [TxHash])]+affectedAddrsExpected =+  [ (Address "addr1q9ld26v2lv8wvrxxmvg90pn8n8n5k6tdst06q2s856rwmvnueldzuuqmnsye359fqrk8hwvenjnqultn7djtrlft7jnq7dy7wv",+     [TxHash "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dce628516157f0"])+  , (Address "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",+     [TxHash "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dce628516157d0"])+  ]