๐ src/web3/subscription/patch-codec.ts
D-OPEN SOVEREIGN
Documentation & Insights
Converts a raw on-chain patch batch โ the `{ compressedActions, indexes,
stringIndexes }` triplet returned by BackupStorage.loadActions* and carried
opaquely on `Patch.raw` (O3, spec ยง15.2) โ into the models_v2 `EvmPayload`
codec shape `deserializePatches()` expects.1import type { EvmPayload } from '../../models/binary';
2import type { Patch } from './types';
3
4/**
5 * Converts a raw on-chain patch batch โ the `{ compressedActions, indexes,
6 * stringIndexes }` triplet returned by BackupStorage.loadActions* and carried
7 * opaquely on `Patch.raw` (O3, spec ยง15.2) โ into the models_v2 `EvmPayload`
8 * codec shape `deserializePatches()` expects.
9 */
10export function patchToEvmPayload(patch: Patch, version: number): EvmPayload {
11 const raw = patch.raw as { compressedActions: bigint[]; indexes: bigint[]; stringIndexes: string[] };
12 return {
13 version,
14 patches: raw.compressedActions,
15 textIndex: raw.indexes.map(Number),
16 textData: raw.stringIndexes,
17 };
18}
19