Agoric / BytePitchPartnerEng

For engineering items partnered with BytePitch. Primarily for project management and tracking
0 stars 0 forks source link

`manutalTimer` vat in `a3p-integration` #36

Open anilhelvaci opened 3 hours ago

anilhelvaci commented 3 hours ago

Problem Definition

We need to agree on how the manualTimer vat will look like.

Discussion

// @ts-check
import { Far } from '@endo/marshal';
import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';
import { TimeMath } from '@agoric/time';

export const start = async zcf => {
  const { startValue, timeStep } = zcf.getTerms();

  const manualTimer = buildManualTimer(console.log, startValue, timeStep);

  const advanceTimeHandler = async (seat, offerArgs) => {
    const { timestamp: timeRaw } = offerArgs;
    const timestamp = TimeMath.coerceTimestampRecord(
      timeRaw,
      manualTimer.getTimerBrand(),
    );
    await manualTimer.advanceTo(timestamp, 'New Time');
    return `Time advanced to ${timestamp}`;
  };

  const advanceTimeByHandler = async (seat, offerArgs) => {
    const { duration } = offerArgs;
    const timeBlock = TimeMath.coerceRelativeTimeRecord(
      duration,
      manualTimer.getTimerBrand(),
    );

    manualTimer.advanceBy(timeBlock, `Advance time by ${timeBlock.relValue}`);

    return 'Successfully advanced the time progressively';
  };

  const creatorFacet = Far('creatorFacet', {});

  const publicFacet = Far('publicFacet', {
    getManualTimer: () => manualTimer,
    getCurrentTimestamp: () => manualTimer.getCurrentTimestamp(),
    makeAdvanceTimeInvitation: () =>
      zcf.makeInvitation(advanceTimeHandler, 'advanceTimeHandler'),
    makeAdvanceTimeStepByStepInvitation: () =>
      zcf.makeInvitation(advanceTimeByHandler, 'advanceTimeByHandler'),
  });

  return harden({ creatorFacet, publicFacet });
};

Above is what we have used to wrap around manualTimer. See this for the whole usage.

Which manualTimer did we use?

In the code above, we import buildManualTimer like;

import buildManualTimer from '@agoric/zoe/tools/manualTimer.js';

However, when you go to the source you can see that @agoric/zoe/tools/manualTimer.js inherits its functionality from @agoric/swingset-vat/tools/manual-timer.js

Questions

Where should this vat code go in agoric-sdk?

TBD

anilhelvaci commented 3 hours ago

Pleas let me know what you think @dckc, @turadg, @Chris-Hibbert

turadg commented 1 hour ago

We need to agree on how the manualTimer vat will look like.

We need to figure out more than that. https://github.com/Agoric/BytePitchPartnerEng/issues/35#issuecomment-2452110986

Let's take this off Github until we have a design. There are too many tickets to keep track of.