CardanoSolutions / ogmios

❇️ A WebSocket JSON/RPC bridge for Cardano
https://ogmios.dev
Mozilla Public License 2.0
304 stars 90 forks source link

[TypeScript client] Tx body's fee field type is different between compile-time and run-time #274

Closed longngn closed 2 years ago

longngn commented 2 years ago

What Git revision are you using?

v5.5.5

What operating system are you using, and which version?

Describe what the problem is?

The fee field is bigint in type definition but is number in runtime

How to reproduce:

import {
  createInteractionContext,
  createChainSyncClient,
  InteractionContext,
  isBabbageBlock,
} from "@cardano-ogmios/client";
import { Block, PointOrOrigin, TipOrOrigin } from "@cardano-ogmios/schema";

async function main() {
  const context: InteractionContext = await createInteractionContext(
    (err) => console.error(err),
    () => console.log("Connection closed."),
    { connection: { host: "localhost", port: 1337 } }
  );

  const rollForward = async ({ block }: { block: Block }) => {
    if (!isBabbageBlock(block)) {
      return;
    }
    console.log(typeof block.babbage.body[0].body.fee);
  };

  const rollBackward = async (
    { point, tip }: { point: PointOrOrigin; tip: TipOrOrigin },
    requestNext: () => void
  ): Promise<void> => {
    console.log(`Rollback`);
    requestNext();
  };

  const client = await createChainSyncClient(context, {
    rollForward,
    rollBackward,
  });

  await client.startSync([
    {
      hash: "a79840042fe89e50c4ac4f367dae06d161a6ed6b561d354cd4b036de87a84142",
      slot: 74588465,
    },
  ]);
}

main();

What should be the expected behavior?

KtorZ commented 2 years ago

Thanks for reporting! This came from a pretty old commit (ed1d137329a0d787804ac06b3af437139e31bb31) where the TypeScript client parser didn't not get updated properly to turn those into bigint.

This is now covered with additional test cases in ad12397