// SPDX-FileCopyrightText: © 2026 LEDGER SAS
// SPDX-License-Identifier: Apache-2.0

import type { TezosContext } from '../config'
import type { BlockInfo } from '@ledgerhq/coin-module-framework/api/index'
import { createTzktApi } from '../network/tzkt'

export async function lastBlock(context: TezosContext): Promise<BlockInfo> {
  const config = await context.config()
  const result = await createTzktApi(config).getLastBlock()

  return {
    height: result.level,
    hash: result.hash,
    time: result.date,
  }
}
