Skip to content
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
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [unreleased]

- Add `GET` endpoint `/v0/blockInfo/{blockHash}` for getting block information for a given block hash.

- 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.

## [0.45.0] - 2026-02-23
Expand Down
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ cooldowns and the available balance) and get the info if an account is on any al
* `POST /v0/transakOnRamp`: create a URL to initiate purchasing CCDs through the Transak on-ramp.
* `GET /v0/genesisHash`: get the genesis block hash for the connected network.
* `GET /v0/consensusInfo`: get the current consensus status from the node.
* `GET /v0/blockInfo/{blockHash}`: get block information for a given block hash.

### Errors

Expand Down Expand Up @@ -1545,6 +1546,60 @@ Example response (protocol version 6+):
}
```

## Block info

A GET request to `/v0/blockInfo/{blockHash}` returns information about the block with the given hash.

Returns `404 Not Found` if no block with the given hash exists.

The response includes:

| Field | Type | Description |
|---|---|---|
| `blockHash` | string (hex) | Hash of the block |
| `blockParent` | string (hex) | Hash of the parent block |
| `blockLastFinalized` | string (hex) | Hash of the last finalized block at the time this block was baked |
| `blockHeight` | number | Absolute height of the block |
| `genesisIndex` | number | Number of protocol updates preceding this block |
| `eraBlockHeight` | number | Height of this block relative to the (re)genesis block of its era |
| `blockReceiveTime` | string (ISO 8601) | Time the block was received |
| `blockArriveTime` | string (ISO 8601) | Time the block was verified |
| `blockSlotTime` | string (ISO 8601) | Nominal time of the slot in which the block was baked |
| `blockBaker` | number or null | Identifier of the block baker, or `null` for a genesis block |
| `finalized` | boolean | Whether the block is finalized |
| `transactionCount` | number | Number of transactions in the block |
| `transactionEnergyCost` | number | Total energy cost of transactions in the block |
| `transactionsSize` | number | Total size of transactions in the block (bytes) |
| `blockStateHash` | string (hex) | Hash of the block state |
| `protocolVersion` | number | Protocol version of the block |

Additionally, `blockSlot` (slot number) is included for protocol versions 1–5, and `round` and `epoch` are included for protocol version 6 and later.

Example response:

```json
{
"blockHash": "63e2571547f8e9b7dbef849ab5fce5eae7fe96a1ab94b52e1adcb62adcab3e42",
"blockParent": "a5e75c2419f539dfbde1fcc41c2c2b8dd1b9f0a0d4a2fd3d5e52c75a1b00000",
"blockLastFinalized": "a5e75c2419f539dfbde1fcc41c2c2b8dd1b9f0a0d4a2fd3d5e52c75a1b00000",
"blockHeight": 12345678,
"genesisIndex": 5,
"eraBlockHeight": 100000,
"blockReceiveTime": "2024-01-15T12:00:01Z",
"blockArriveTime": "2024-01-15T12:00:01Z",
"blockSlotTime": "2024-01-15T12:00:00Z",
"blockBaker": 42,
"finalized": true,
"transactionCount": 3,
"transactionEnergyCost": 6000,
"transactionsSize": 512,
"blockStateHash": "9dd9aee09a3b6d9c3f48e4f3df4f8b2c1e4d7a9b2f6c8e1d3a5b7c9e2f4a6b8",
"protocolVersion": 6,
"round": 42,
"epoch": 100
}
```

# Deployment

The wallet proxy must have access to
Expand Down
1 change: 1 addition & 0 deletions src/Internationalization/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data ErrorMessage
| EMTransactionRejected
| EMMalformedTransaction
| EMMalformedAddress
| EMMalformedBlockHash
| EMDatabaseError
| EMAccountNotFinal
| EMConfigurationError
Expand Down
1 change: 1 addition & 0 deletions src/Internationalization/En.hs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ translation = I18n{..}
i18nErrorMessage EMTransactionRejected = "Transaction rejected by the node"
i18nErrorMessage EMMalformedTransaction = "Malformed transaction hash"
i18nErrorMessage EMMalformedAddress = "Malformed account address"
i18nErrorMessage EMMalformedBlockHash = "Malformed block hash"
i18nErrorMessage EMDatabaseError = "Database error"
i18nErrorMessage EMAccountNotFinal = "Account creation is not finalized"
i18nErrorMessage EMConfigurationError = "Server configuration error"
Expand Down
16 changes: 16 additions & 0 deletions src/Proxy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ mkYesod
/v0/transakOnRamp TransakOnRamp POST
/v0/genesisHash GenesisHash GET
/v0/consensusInfo ConsensusInfoR GET
/v0/blockInfo/#Text BlockInfoR GET
|]

instance Yesod Proxy where
Expand Down Expand Up @@ -3014,6 +3015,21 @@ getConsensusInfoR =
"triggerBlockTime" .= cbftsTriggerBlockTime bft
]

-- | Returns block information for the block with the given hash.
-- Returns 404 if no block with the given hash exists.
-- If the block hash could not be parsed, a HTTP response with status code @400@ is returned.
getBlockInfoR :: Text -> Handler TypedContent
getBlockInfoR hashText =
case readMaybe (Text.unpack hashText) of
Nothing -> respond400Error EMMalformedBlockHash RequestInvalid
Just blockHash ->
runGRPCWithCustomError
(Just (StatusNotOkError NOT_FOUND, Just notFound404, Nothing, Just $ EMErrorResponse NotFound))
(getBlockInfo (Given blockHash))
$ \blockInfo -> do
$(logOther "Trace") "Successfully got block info."
sendResponse $ toJSON blockInfo

-- | Create a Transak on-ramp session. This requires an "address" parameter to be specified, which
-- will be the address of the account to which the purchased funds will be sent.
postTransakOnRamp :: Handler TypedContent
Expand Down
Loading