]> git.codecow.com Git - libnemo.git/commitdiff
Build out more of blocks_info req/res.
authorChris Duncan <chris@codecow.com>
Tue, 11 Aug 2026 04:54:05 +0000 (21:54 -0700)
committerChris Duncan <chris@codecow.com>
Tue, 11 Aug 2026 04:54:05 +0000 (21:54 -0700)
src/lib/rpc/block_info.ts
src/lib/rpc/blocks_info.ts
src/lib/wallet/refresh.ts

index 35e064e06e05b1ab23f3658f0c89c6fffa737c82..18bdcb6f7db52fe2ff5849cc870572a0b0c9b989 100644 (file)
@@ -32,6 +32,7 @@ export type BlockInfoResponse = {
        height: string
        linked_account: string
        local_timestamp: string
+       receive_hash?: Hex | '0'
        subtype: 'change' | 'epoch' | 'open' | 'receive' | 'send'
        successor: string
 }
@@ -72,6 +73,9 @@ export function block_info (body: unknown): BlockInfoResponse {
                        response.local_timestamp = body.local_timestamp
                        response.subtype = body.subtype
                        response.successor = body.successor
+                       if ('receive_hash' in body && (hex.is(body.receive_hash, 64) || body.receive_hash === '0')) {
+                               response.receive_hash = body.receive_hash
+                       }
 
                        const contents: BlockInfoContents = Object.create(null)
                        contents.account = body.contents.account
index 7f354b81a76e17879325de829b0cbf10971e840c..0df6aeaebd3de9f0b42cfaa0dd8950ac71c3f659 100644 (file)
@@ -6,12 +6,24 @@ import { hex } from '../convert'
 import { RpcError } from '../errors'
 import { BlockInfoResponse, block_info } from './block_info'
 
+export type BlocksInfoRequest = {
+       hashes: Hex[]
+       include_linked_account: true
+       include_not_found: true
+       json_block: true
+       pending: true
+       receivable: true
+       receive_hash: true
+       source: true
+}
+
 export type BlocksInfoResponse = {
        blocks?: {
                [hash: Hex]: BlockInfoResponse
        }
+       blocks_not_found?: Hex[]
        errors?: {
-               [hash: string]: string
+               [hash: Hex]: string
        }
 }
 
@@ -29,6 +41,16 @@ export function blocks_info (body: unknown): BlocksInfoResponse {
                        }
                }
 
+               if ('blocks_not_found' in body && Array.isArray(body.blocks_not_found)) {
+                       const blocks_not_found = response.blocks_not_found ?? Object.create(null)
+                       response.blocks_not_found = blocks_not_found
+                       for (const hash of body.blocks_not_found as unknown[]) {
+                               if (hex.is(hash, 64)) {
+                                       blocks_not_found.push(hash)
+                               }
+                       }
+               }
+
                if ('blocks' in body && body.blocks != null && typeof body.blocks === 'object') {
                        const blocks: Record<Hex, BlockInfoResponse> = response.blocks ?? Object.create(null)
                        response.blocks = blocks
index 0ced0601bb0207c32e6460946cbd3c91f1e3bf0d..8eab352be7134984252520b048dbf6637bcb371d 100644 (file)
@@ -6,7 +6,7 @@ import { Block } from '../block'
 import { Rpc } from '../rpc'
 import { AccountInfoRequest, AccountInfoResponse } from '../rpc/account_info'
 import { AccountsFrontiersResponse } from '../rpc/accounts_frontiers'
-import { BlocksInfoResponse } from '../rpc/blocks_info'
+import { BlocksInfoRequest, BlocksInfoResponse } from '../rpc/blocks_info'
 import { Wallet } from '../wallet'
 
 export async function _refresh (wallet: Wallet, rpc: Rpc | string | URL, from: number, to: number): Promise<Map<number, Account>>
@@ -32,9 +32,20 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to:
                        accounts: addresses
                }
                const resAccountsFrontiers: AccountsFrontiersResponse = await rpc.post('accounts_frontiers', data)
-               const frontiers = Object.values(resAccountsFrontiers.frontiers ?? Object.create(null))
+               const frontiers = resAccountsFrontiers.frontiers ? Object.values(resAccountsFrontiers.frontiers) : []
+
+               const reqBlocksInfo: BlocksInfoRequest = {
+                       hashes: frontiers,
+                       include_not_found: true,
+                       json_block: true,
+                       include_linked_account: true,
+                       pending: true,
+                       receivable: true,
+                       receive_hash: true,
+                       source: true
+               }
                const { blocks }: BlocksInfoResponse = frontiers.length > 0
-                       ? await rpc.post('blocks_info', { json_block: true, include_not_found: true, hashes: frontiers })
+                       ? await rpc.post('blocks_info', reqBlocksInfo)
                        : Object.create(null)
 
                for (const account of accounts.values()) {
@@ -74,7 +85,7 @@ export async function _refresh (wallet: Wallet, rpc: unknown, from: unknown, to:
                                        frontierBlock[subtype](link, 0)
                                } else {
                                        throw new TypeError('Invalid frontier block subtype', { cause: subtype })
-                               }       
+                               }
                                frontierBlock.signature = signature
                                account.frontier_block = frontierBlock
                        }