height: string
linked_account: string
local_timestamp: string
+ receive_hash?: Hex | '0'
subtype: 'change' | 'epoch' | 'open' | 'receive' | 'send'
successor: string
}
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
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
}
}
}
}
+ 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
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>>
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()) {
frontierBlock[subtype](link, 0)
} else {
throw new TypeError('Invalid frontier block subtype', { cause: subtype })
- }
+ }
frontierBlock.signature = signature
account.frontier_block = frontierBlock
}