Dean asked for an example of a trivial contract entered into the cosmic-SwingSet Read-Eval-Print loop to show how contractHost and other facilities available from home can be experimented with there.
I started with this trivial contract:
/* global makePromise */
// Copyright (C) 2019 Agoric, under Apache License 2.0
import harden from '@agoric/harden';
const doubler = harden({
start: (_, inviteMaker) => {
const result = makePromise();
const seat = harden({
provide(n) { result.res(2*n); },
result() { return result.p; },
});
return harden({
seat: inviteMaker.make('multiplicand', seat),
});
},
});
const doublerSrcs = harden({ start: `${doubler.start}` });
export { doublerSrcs };
Ignoring false starts and dead-ends, I had this interaction with the REPL:
command[2]
d1 = { start: (, inviteMaker) => { const result = makePromise(); const seat = harden({ provide(n) { result.res(2*n); }, result() { return result.p; }, }); return harden({ seat: inviteMaker.make('multiplicand', seat), }); }, }
history[2]
{"start":[Function start]}
command[3]
d1Srcs = { start: `${d1.start}` };
history[3]
{"start":"(, inviteMaker) => {\n const result = makePromise();\n const seat = harden({\n provide(n) {\n result.res(2 * n);\n },\n\n result() {\n return result.p;\n }\n\n });\n return harden({\n seat: inviteMaker.make('multiplicand', seat)\n });\n }"}
command[4]
triv1 = home.contractHost~.install(d1Srcs)
history[4]
[Presence o-56]
command[5]
triv1~.spawn({})
history[5]
{"seat":[Presence o-57]}
command[6]
home
history[6]
{"gallery":[Presence o-50],"handoffService":[Presence o-51],"purse":[Presence o-52],"canvasStatePublisher":[Presence o-53],"contractHost":[Presence o-54],"handoff":[Presence o-55]}
command[8]
home.purse~.getIssuer()
history[8]
[Presence o-58]
command[17]
iss = home.contractHost~.getInviteIssuer()
history[17]
[Presence o-59]
command[18]
iss~.claimAll(history[5].seat, "seat1")
history[18]
[Presence o-60]
command[20]
seat1P = home.contractHost~.redeem(history[18])
history[20]
[Presence o-61]
command[21]
seat1P~.provide(3)
history[21]
undefined
command[22]
seat1P~.result()
history[22]
6
Notice that line 2 drops const
and the outer harden
from the source file.