]> git.codecow.com Git - libnemo.git/commitdiff
Explicitly call appropriate block subtype function when refreshing account frontiers.
authorChris Duncan <chris@codecow.com>
Sat, 8 Aug 2026 21:29:57 +0000 (14:29 -0700)
committerChris Duncan <chris@codecow.com>
Sat, 8 Aug 2026 21:29:57 +0000 (14:29 -0700)
src/lib/account/refresh.ts
src/lib/block/index.ts
src/lib/wallet/refresh.ts

index a34c03fec05b1f89ace55baf13e85120359ceb6d..35329b3921d7e829b26c22853d3d8c122a0ba9ad 100644 (file)
@@ -3,7 +3,6 @@
 
 import { Account } from '.'
 import { Block } from '../block'
-import { BURN_PUBLIC_KEY } from '../constants'
 import { Rpc } from '../rpc'
 import { AccountInfoRequest } from '../rpc/account_info'
 import { BlockInfoRequest } from '../rpc/block_info'
@@ -55,7 +54,14 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
        if (typeof confirmedFrontierBlock[confirmedFrontierSubtype] !== 'function') {
                throw new TypeError('Unknown subtype of confirmed frontier block', { cause: confirmedFrontierSubtype })
        }
-       confirmedFrontierBlock[confirmedFrontierSubtype](confirmedFrontierContents.link === BURN_PUBLIC_KEY ? confirmedFrontierContents.representative : confirmedFrontierContents.link, 0).signature = confirmedFrontierContents.signature
+       if (confirmedFrontierSubtype === 'epoch') {
+               confirmedFrontierBlock.epoch(accountInfo.account_version)
+       } else if (confirmedFrontierSubtype === 'change') {
+               confirmedFrontierBlock.change(confirmedFrontierContents.representative)
+       } else {
+               confirmedFrontierBlock[confirmedFrontierSubtype](confirmedFrontierContents.link, 0)
+       }
+       confirmedFrontierBlock.signature = confirmedFrontierContents.signature
        account.confirmed_frontier_block = confirmedFrontierBlock
 
        const reqFrontierBlockInfo: BlockInfoRequest = {
@@ -85,6 +91,13 @@ export async function _refresh (account: Account, rpc: unknown): Promise<void> {
        if (typeof frontierBlock[frontierSubtype] !== 'function') {
                throw new TypeError('Unknown subtype of frontier block', { cause: frontierSubtype })
        }
-       frontierBlock[frontierSubtype](frontierContents.link === BURN_PUBLIC_KEY ? frontierContents.representative : frontierContents.link, 0).signature = frontierContents.signature
+       if (frontierSubtype === 'epoch') {
+               frontierBlock.epoch(accountInfo.account_version)
+       } else if (confirmedFrontierSubtype === 'change') {
+               frontierBlock.change(frontierContents.representative)
+       } else {
+               frontierBlock[frontierSubtype](frontierContents.link, 0)
+       }
+       frontierBlock.signature = frontierContents.signature
        account.frontier_block = frontierBlock
 }
index 8e8d89959db97e25066395dc45a1e39eb23e760d..bb8a8931e4560177285cc89a6a0de9ca0cba5e81 100644 (file)
@@ -171,7 +171,7 @@ export class Block {
         *
         * @returns {Block} This block unchanged
         */
-       epoch (version: 1 | 2): Block {
+       epoch (version: 1 | 2 | '1' | '2'): Block {
                const special = utf8.toHex(`epoch v${version} block`)
                this.link = hex.toBytes(`${special}000000000000000000000000000000000000`)
                this.subtype = 'epoch'
index 28473a29efbb68170c513e2be22f35fc2d1e48d4..98594c253f742e285691d07e6f29129fb401eb33 100644 (file)
@@ -61,8 +61,14 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to:
                                if (typeof frontierBlock[subtype] !== 'function') {
                                        throw new TypeError('Unknown frontier block subtype', { cause: subtype })
                                }
-                               const arg = subtype === 'epoch' ? account_version : subtype === 'change' ? representative : link
-                               frontierBlock[subtype](arg, 0).signature = signature
+                               if (subtype === 'epoch') {
+                                       frontierBlock.epoch(account_version)
+                               } else if (subtype === 'change') {
+                                       frontierBlock.change(representative)
+                               } else {
+                                       frontierBlock[subtype](link, 0)
+                               }
+                               frontierBlock.signature = signature
                                account.frontier_block = frontierBlock
                        }
                }