Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: add GET /txs/{hash}/cbor endpoint #63

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions blockfrost-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Version [next](https://github.com/blockfrost/blockfrost-haskell/compare/api-0.11.0.0...master) (2024-MM-DD)

* Additions [#63](https://github.com/blockfrost/blockfrost-haskell/pull/63)
* `/txs/:hash/cbor` endpoint with `TransactionCBOR` data type

# Version [0.11.0.0](https://github.com/blockfrost/blockfrost-haskell/compare/api-0.10.0.0...api-0.11.0.0) (2024-08-26)

Changes
Expand Down
7 changes: 7 additions & 0 deletions blockfrost-api/src/Blockfrost/API/Cardano/Transactions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ data TransactionsAPI route =
:> Capture "hash" TxHash
:> "metadata"
:> Get '[JSON] [TransactionMetaJSON]
, _txCBOR
:: route
:- Summary "Transaction in CBOR"
:> Description "Obtain the CBOR serialized transaction."
:> Capture "hash" TxHash
:> "cbor"
:> Get '[JSON] [TransactionCBOR]
, _txMetadataCBOR
:: route
:- Summary "Transaction metadata in CBOR"
Expand Down
1 change: 1 addition & 0 deletions blockfrost-api/src/Blockfrost/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ makeFields ''TransactionPoolUpdate
makeFields ''PoolUpdateMetadata
makeFields ''TransactionPoolRetiring
makeFields ''TransactionMetaJSON
makeFields ''TransactionCBOR
makeFields ''TransactionMetaCBOR
makeFields ''TransactionRedeemer

Expand Down
12 changes: 12 additions & 0 deletions blockfrost-api/src/Blockfrost/Types/Cardano/Transactions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Blockfrost.Types.Cardano.Transactions
, PoolUpdateMetadata (..)
, TransactionPoolRetiring (..)
, TransactionMetaJSON (..)
, TransactionCBOR (..)
, TransactionMetaCBOR (..)
) where

Expand Down Expand Up @@ -367,6 +368,17 @@ instance ToSample TransactionMetaJSON where
(Just $ oracleMeta "0.15409850555139935")
]

-- | Transaction in CBOR
newtype TransactionCBOR = TransactionCBOR { _transactionCBORCbor :: Text }
deriving stock (Show, Eq, Generic)
deriving (FromJSON, ToJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix "_transactionCBOR", CamelToSnake]] TransactionCBOR

instance ToSample TransactionCBOR where
toSamples = pure $ singleSample $
TransactionCBOR
"a100a16b436f6d62696e6174696f6e8601010101010c"

-- | Transaction metadata in CBOR
data TransactionMetaCBOR = TransactionMetaCBOR
{ _transactionMetaCBORLabel :: Text -- ^ Metadata label
Expand Down
15 changes: 15 additions & 0 deletions blockfrost-api/test/Cardano/Transactions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ spec_txs = do
`shouldBe`
Right transactionMetaJSONExpected

it "parses transaction (CBOR) sample" $ do
eitherDecode transactionCBORSample
`shouldBe`
Right transactionCBORExpected

it "parses transaction meta (CBOR) sample" $ do
eitherDecode transactionMetaCBORSample
`shouldBe`
Expand Down Expand Up @@ -429,6 +434,16 @@ transactionMetaJSONExpected =
(Just $ oracleMeta "0.15409850555139935")
]

transactionCBORSample = [r|
{
"cbor": "a100a16b436f6d62696e6174696f6e8601010101010c"
}
|]

transactionCBORExpected =
TransactionCBOR
"a100a16b436f6d62696e6174696f6e8601010101010c"

transactionMetaCBORSample = [r|
{
"label": "1968",
Expand Down
3 changes: 3 additions & 0 deletions blockfrost-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Version [next](https://github.com/blockfrost/blockfrost-haskell/compare/client-0.8.0.1...master) (2024-MM-DD)

* Additions [#63](https://github.com/blockfrost/blockfrost-haskell/pull/63)
* `getTxCBOR` for `/txs/:hash/cbor`

# Version [0.8.0.1](https://github.com/blockfrost/blockfrost-haskell/compare/client-0.8.0.0...client-0.8.0.1) (2024-01-16)

* GHC 9.6.3 compatibility
Expand Down
1 change: 1 addition & 0 deletions blockfrost-client/src/Blockfrost/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ module Blockfrost.Client
, getTxPoolUpdates
, getTxPoolRetiring
, getTxMetadataJSON
, getTxCBOR
, getTxMetadataCBOR
, getTxRedeemers
, submitTx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Blockfrost.Client.Cardano.Transactions
, getTxPoolUpdates
, getTxPoolRetiring
, getTxMetadataJSON
, getTxCBOR
, getTxMetadataCBOR
, submitTx
) where
Expand Down Expand Up @@ -92,6 +93,13 @@ getTxMetadataJSON_ = _txMetadataJSON . transactionsClient
getTxMetadataJSON :: MonadBlockfrost m => TxHash -> m [TransactionMetaJSON]
getTxMetadataJSON t = go (`getTxMetadataJSON_` t)

getTxCBOR_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionCBOR]
getTxCBOR_ = _txCBOR . transactionsClient

-- | Get transaction in CBOR
getTxCBOR :: MonadBlockfrost m => TxHash -> m [TransactionCBOR]
getTxCBOR t = go (`getTxCBOR_` t)

getTxMetadataCBOR_ :: MonadBlockfrost m => Project -> TxHash -> m [TransactionMetaCBOR]
getTxMetadataCBOR_ = _txMetadataCBOR . transactionsClient

Expand Down