Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

fix: add Far() where necessary #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// @ts-check
import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';
import { makeWebSocketHandler } from './lib-http';

const spawnHandler = (
{ creatorFacet, board, http, invitationIssuer },
_invitationMaker,
) =>
makeWebSocketHandler(http, (send, _meta) =>
harden({
Far('connectionHandler', {
async onMessage(obj) {
switch (obj.type) {
case 'fungibleFaucet/sendInvitation': {
Expand Down
9 changes: 5 additions & 4 deletions api/src/lib-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

// @ts-check
import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';

export const makeWebSocketHandler = (http, makeConnectionHandler) => {
return harden({
return Far('webSocketHandler', {
// This creates the commandHandler for the http service to handle inbound
// websocket requests.
getCommandHandler() {
const channelToConnHandler = new WeakMap();
const handler = {
const handler = Far('httpCommandHandler', {
// Executed upon an error in handling the websocket.
onError(obj, { channelHandle }) {
const connHandler = channelToConnHandler.get(channelHandle);
Expand Down Expand Up @@ -43,8 +44,8 @@ export const makeWebSocketHandler = (http, makeConnectionHandler) => {
const connHandler = channelToConnHandler.get(channelHandle);
return connHandler.onMessage(obj);
},
};
return harden(handler);
});
return handler;
},
});
};
9 changes: 5 additions & 4 deletions contract/src/contract.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import '@agoric/zoe/exported';
import { Far } from '@agoric/marshal';

/**
* This is a very simple contract that creates a new issuer and mints payments
Expand Down Expand Up @@ -37,18 +38,18 @@ const start = async (zcf) => {
return 'Offer completed. You should receive a payment from Zoe';
};

const creatorFacet = {
const creatorFacet = Far('creatorFacet', {
// The creator of the instance can send invitations to anyone
// they wish to.
makeInvitation: () => zcf.makeInvitation(mintPayment, 'mint a payment'),
getTokenIssuer: () => issuer,
};
});

const publicFacet = {
const publicFacet = Far('publicFacet', {
// Make the token issuer public. Note that only the mint can
// make new digital assets. The issuer is ok to make public.
getTokenIssuer: () => issuer,
};
});

// Return the creatorFacet to the creator, so they can make
// invitations for others to get payments of tokens. Publish the
Expand Down