@effectstream/sync 0.103.2 → 0.104.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/sync",
3
- "version": "0.103.2",
3
+ "version": "0.104.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -13,10 +13,10 @@
13
13
  },
14
14
  "exports": "./src/mod.ts",
15
15
  "dependencies": {
16
- "@effectstream/config": "0.103.2",
17
- "@effectstream/db": "0.103.2",
18
- "@effectstream/log": "0.103.2",
19
- "@effectstream/utils": "0.103.2",
16
+ "@effectstream/config": "0.104.0",
17
+ "@effectstream/db": "0.104.0",
18
+ "@effectstream/log": "0.104.0",
19
+ "@effectstream/utils": "0.104.0",
20
20
  "@midnight-ntwrk/ledger-v8": "8.1.0",
21
21
  "@midnight-ntwrk/midnight-js-indexer-public-data-provider": "4.1.1",
22
22
  "@midnight-ntwrk/onchain-runtime": "npm:@midnight-ntwrk/onchain-runtime-v3@3.0.0",
@@ -415,19 +415,31 @@ export class MidnightFetcher extends BaseDataFetcher<
415
415
  return c.address.padStart(longest, '0') === contractAddress.padStart(longest, '0');
416
416
  })!.state!;
417
417
  const primitive = primitiveEntry.primitive;
418
- const f = primitive.contract ?? { ledger: (_: StateValue): Record<string, any> => ({}) };
418
+ const f = primitive.contract;
419
419
  const ledgerFromTxStateHex = (f as {
420
420
  ledgerFromTxStateHex?: (rawHexState: string) => Record<string, any>;
421
- }).ledgerFromTxStateHex;
421
+ } | undefined)?.ledgerFromTxStateHex;
422
422
  let state: Record<string, any>;
423
- if (typeof ledgerFromTxStateHex === "function") {
424
- state = ledgerFromTxStateHex(rawState);
425
- } else {
426
- const byteState = new Uint8Array(rawState.match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)));
427
- const contractState = ContractState.deserialize(byteState);
428
- const stateValue = contractState.data.state;
429
- const additionalFields = primitive.parseAdditionalLedgerFields?.(stateValue) ?? {};
430
- state = { ...f.ledger(stateValue), ...additionalFields };
423
+ try {
424
+ if (typeof ledgerFromTxStateHex === "function") {
425
+ state = ledgerFromTxStateHex(rawState);
426
+ } else {
427
+ const hexBytes = rawState.match(/.{1,2}/g);
428
+ if (!hexBytes) throw new Error("contract state is empty");
429
+ const byteState = new Uint8Array(hexBytes.map(byte => parseInt(byte, 16)));
430
+ const contractState = ContractState.deserialize(byteState);
431
+ const stateValue = contractState.data.state;
432
+ const generatedFields = f?.ledger(stateValue) ?? {};
433
+ const schemaFields = primitive.parseAdditionalLedgerFields?.(stateValue) ?? {};
434
+ state = { ...generatedFields, ...schemaFields };
435
+ }
436
+ } catch (error) {
437
+ throw new Error(
438
+ `Failed to decode Midnight contract ${contractAddress} at block ${height}, transaction ${t.hash}: ${
439
+ error instanceof Error ? error.message : String(error)
440
+ }`,
441
+ { cause: error },
442
+ );
431
443
  }
432
444
  return {
433
445
  syncProtocol: {
@@ -17,7 +17,8 @@ import { UtxoRpcSyncState } from "./sync-protocols/utxorpc/state.ts";
17
17
  import { isEffectiveServerPredicate, predicateKey } from "./sync-protocols/utxorpc/utils.ts";
18
18
  import type { UtxorpcTxPredicate } from "@effectstream/config";
19
19
  import type { PrimitiveEntryType } from "./sync-protocols/utxorpc/types.ts";
20
- import { MidnightFetcher, MidnightSyncState } from "@effectstream/sync";
20
+ import { MidnightFetcher } from "./sync-protocols/midnight/fetcher.ts";
21
+ import { MidnightSyncState } from "./sync-protocols/midnight/state.ts";
21
22
  import { AvailFetcher } from "./sync-protocols/avail/fetcher.ts";
22
23
  import { AvailSyncState } from "./sync-protocols/avail/state.ts";
23
24
  import { NtpFetcher } from "./sync-protocols/ntp/fetcher.ts";