//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
//! SPDX-License-Identifier: GPL-3.0-or-later
-import { APDU_CODES, LedgerResponse, LedgerTransport, STATUS_CODES, LISTEN_TIMEOUT, OPEN_TIMEOUT } from '.'
+import { APDU_CODES, LedgerResponse, LedgerTransport, LISTEN_TIMEOUT, OPEN_TIMEOUT, STATUS_CODES } from '.'
import { Account } from '../account'
import { Block } from '../block'
import { BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET } from '../constants'
if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) {
throw new TypeError('Invalid account index')
}
- if (!(block instanceof Block)) {
- throw new TypeError('Invalid block format')
- }
if (!(block.link instanceof Uint8Array)) {
throw new TypeError('Invalid block link')
}
* @param {Rpc} rpc - Rpc class object with a node URL
*/
static async updateCache (index: number, hash: string, rpc: Rpc): Promise<LedgerResponse>
- static async updateCache (index: number, input: any, node?: Rpc): Promise<LedgerResponse> {
+ static async updateCache (index: number, input: unknown, node?: Rpc): Promise<LedgerResponse> {
if (typeof input === 'string' && node instanceof Rpc) {
const data = {
'json_block': 'true',
if (!res || !res.ok || res.error) {
throw new Error(`Unable to fetch block info`, res)
}
- input = res.contents
+ const { contents: { account, balance, link, previous, representative, signature } } = res
+ const block = new Block(account, balance, previous, representative).receive(link, 0)
+ block.signature = signature
+ input = block
+ }
+ if (!(input instanceof Block)) {
+ throw new TypeError('Invalid block format')
}
return queue<LedgerResponse>(async () => _cache(this.#transport, index, input))
}