Skip to content

Commit 28d5c33

Browse files
committed
feat: add GET /v0/blockInfo/{blockHash} endpoint
Add a new endpoint that returns block information for a given block hash. The response uses the existing BlockInfo type which already has a ToJSON instance, so the full block metadata is returned directly. Returns 404 if no block with the given hash exists. Returns 400 if the provided hash is malformed.
1 parent 1ab46a1 commit 28d5c33

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [unreleased]
44

5+
- Add `GET` endpoint `/v0/blockInfo/{blockHash}` for getting block information for a given block hash.
6+
57
- Add `GET` endpoint `/v0/consensusInfo` for getting the current consensus status from the node, including last finalized block, best block, protocol version, and timing parameters.
68

79
## [0.45.0] - 2026-02-23

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ cooldowns and the available balance) and get the info if an account is on any al
5454
* `POST /v0/transakOnRamp`: create a URL to initiate purchasing CCDs through the Transak on-ramp.
5555
* `GET /v0/genesisHash`: get the genesis block hash for the connected network.
5656
* `GET /v0/consensusInfo`: get the current consensus status from the node.
57+
* `GET /v0/blockInfo/{blockHash}`: get block information for a given block hash.
5758

5859
### Errors
5960

@@ -1545,6 +1546,60 @@ Example response (protocol version 6+):
15451546
}
15461547
```
15471548

1549+
## Block info
1550+
1551+
A GET request to `/v0/blockInfo/{blockHash}` returns information about the block with the given hash.
1552+
1553+
Returns `404 Not Found` if no block with the given hash exists.
1554+
1555+
The response includes:
1556+
1557+
| Field | Type | Description |
1558+
|---|---|---|
1559+
| `blockHash` | string (hex) | Hash of the block |
1560+
| `blockParent` | string (hex) | Hash of the parent block |
1561+
| `blockLastFinalized` | string (hex) | Hash of the last finalized block at the time this block was baked |
1562+
| `blockHeight` | number | Absolute height of the block |
1563+
| `genesisIndex` | number | Number of protocol updates preceding this block |
1564+
| `eraBlockHeight` | number | Height of this block relative to the (re)genesis block of its era |
1565+
| `blockReceiveTime` | string (ISO 8601) | Time the block was received |
1566+
| `blockArriveTime` | string (ISO 8601) | Time the block was verified |
1567+
| `blockSlotTime` | string (ISO 8601) | Nominal time of the slot in which the block was baked |
1568+
| `blockBaker` | number or null | Identifier of the block baker, or `null` for a genesis block |
1569+
| `finalized` | boolean | Whether the block is finalized |
1570+
| `transactionCount` | number | Number of transactions in the block |
1571+
| `transactionEnergyCost` | number | Total energy cost of transactions in the block |
1572+
| `transactionsSize` | number | Total size of transactions in the block (bytes) |
1573+
| `blockStateHash` | string (hex) | Hash of the block state |
1574+
| `protocolVersion` | number | Protocol version of the block |
1575+
1576+
Additionally, `blockSlot` (slot number) is included for protocol versions 1–5, and `round` and `epoch` are included for protocol version 6 and later.
1577+
1578+
Example response:
1579+
1580+
```json
1581+
{
1582+
"blockHash": "63e2571547f8e9b7dbef849ab5fce5eae7fe96a1ab94b52e1adcb62adcab3e42",
1583+
"blockParent": "a5e75c2419f539dfbde1fcc41c2c2b8dd1b9f0a0d4a2fd3d5e52c75a1b00000",
1584+
"blockLastFinalized": "a5e75c2419f539dfbde1fcc41c2c2b8dd1b9f0a0d4a2fd3d5e52c75a1b00000",
1585+
"blockHeight": 12345678,
1586+
"genesisIndex": 5,
1587+
"eraBlockHeight": 100000,
1588+
"blockReceiveTime": "2024-01-15T12:00:01Z",
1589+
"blockArriveTime": "2024-01-15T12:00:01Z",
1590+
"blockSlotTime": "2024-01-15T12:00:00Z",
1591+
"blockBaker": 42,
1592+
"finalized": true,
1593+
"transactionCount": 3,
1594+
"transactionEnergyCost": 6000,
1595+
"transactionsSize": 512,
1596+
"blockStateHash": "9dd9aee09a3b6d9c3f48e4f3df4f8b2c1e4d7a9b2f6c8e1d3a5b7c9e2f4a6b8",
1597+
"protocolVersion": 6,
1598+
"round": 42,
1599+
"epoch": 100
1600+
}
1601+
```
1602+
15481603
# Deployment
15491604

15501605
The wallet proxy must have access to

src/Internationalization/Base.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ data ErrorMessage
2626
| EMTransactionRejected
2727
| EMMalformedTransaction
2828
| EMMalformedAddress
29+
| EMMalformedBlockHash
2930
| EMDatabaseError
3031
| EMAccountNotFinal
3132
| EMConfigurationError

src/Internationalization/En.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ translation = I18n{..}
291291
i18nErrorMessage EMTransactionRejected = "Transaction rejected by the node"
292292
i18nErrorMessage EMMalformedTransaction = "Malformed transaction hash"
293293
i18nErrorMessage EMMalformedAddress = "Malformed account address"
294+
i18nErrorMessage EMMalformedBlockHash = "Malformed block hash"
294295
i18nErrorMessage EMDatabaseError = "Database error"
295296
i18nErrorMessage EMAccountNotFinal = "Account creation is not finalized"
296297
i18nErrorMessage EMConfigurationError = "Server configuration error"

src/Proxy.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ mkYesod
325325
/v0/transakOnRamp TransakOnRamp POST
326326
/v0/genesisHash GenesisHash GET
327327
/v0/consensusInfo ConsensusInfoR GET
328+
/v0/blockInfo/#Text BlockInfoR GET
328329
|]
329330

330331
instance Yesod Proxy where
@@ -3014,6 +3015,20 @@ getConsensusInfoR =
30143015
"triggerBlockTime" .= cbftsTriggerBlockTime bft
30153016
]
30163017

3018+
-- | Returns block information for the block with the given hash.
3019+
-- Returns 404 if no block with the given hash exists.
3020+
getBlockInfoR :: Text -> Handler TypedContent
3021+
getBlockInfoR hashText =
3022+
case readMaybe (Text.unpack hashText) of
3023+
Nothing -> respond400Error EMMalformedBlockHash RequestInvalid
3024+
Just blockHash ->
3025+
runGRPCWithCustomError
3026+
(Just (StatusNotOkError NOT_FOUND, Just notFound404, Nothing, Just $ EMErrorResponse NotFound))
3027+
(getBlockInfo (Given blockHash))
3028+
$ \blockInfo -> do
3029+
$(logOther "Trace") "Successfully got block info."
3030+
sendResponse $ toJSON blockInfo
3031+
30173032
-- | Create a Transak on-ramp session. This requires an "address" parameter to be specified, which
30183033
-- will be the address of the account to which the purchased funds will be sent.
30193034
postTransakOnRamp :: Handler TypedContent

0 commit comments

Comments
 (0)