Skip to content

Commit

Permalink
Merge pull request Agoric#63 from Agoric/link-installations
Browse files Browse the repository at this point in the history
link installations rather than concating code
  • Loading branch information
erights authored Jun 1, 2019
2 parents af655cb + f109d44 commit 0497ccf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
31 changes: 17 additions & 14 deletions demo/contractHost/coveredCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@

import harden from '@agoric/harden';

import { escrowExchange } from './escrow';

function coveredCall(terms, inviteMaker) {
const [moneyNeeded, stockNeeded, timerP, deadline] = terms;

const [aliceInvite, bobInvite] = escrowExchange(
[moneyNeeded, stockNeeded],
inviteMaker,
const [
escrowExchangeInstallationP,
moneyNeeded,
stockNeeded,
timerP,
deadline,
] = terms;

const pairP = E(escrowExchangeInstallationP).spawn(
harden([moneyNeeded, stockNeeded]),
);

const aliceEscrowSeatP = inviteMaker.redeem(aliceInvite);
const bobEscrowSeatP = inviteMaker.redeem(bobInvite);
const aliceEscrowSeatP = E.resolve(pairP).then(pair =>
inviteMaker.redeem(pair[0]),
);
const bobEscrowSeatP = E.resolve(pairP).then(pair =>
inviteMaker.redeem(pair[1]),
);

// Seats

Expand Down Expand Up @@ -43,10 +50,6 @@ function coveredCall(terms, inviteMaker) {
return inviteMaker.make('writer', bobSeat);
}

const coveredCallSrc = `\
(function() {
${escrowExchange}
return (${coveredCall});
}())`;
const coveredCallSrc = `(${coveredCall})`;

export { coveredCall, coveredCallSrc };
8 changes: 7 additions & 1 deletion demo/contractHost/vat-alice.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ function makeAliceMaker(E, host, log) {
label: inviteIssuerLabel,
quantity: {
installation: coveredCallInstallationP,
terms: [smackers10, yoyodyne7, timerP, 'singularity'],
terms: [
escrowExchangeInstallationP,
smackers10,
yoyodyne7,
timerP,
'singularity',
],
seatIdentity: allegedInviteAmount.quantity.seatIdentity,
seatDesc: 'holder',
},
Expand Down
1 change: 1 addition & 0 deletions demo/contractHost/vat-bob.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function makeBobMaker(E, host, log) {
offerAliceOption(alice) {
log('++ bob.offerAliceOption starting');
const terms = harden([
escrowExchangeInstallationP,
moneyNeededP,
stockNeededP,
timerP,
Expand Down
8 changes: 7 additions & 1 deletion demo/contractHost/vat-fred.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ function makeFredMaker(E, host, log) {
label: inviteIssuerLabel,
quantity: {
installation: coveredCallInstallationP,
terms: [dough10, wonka7, timerP, 'singularity'],
terms: [
escrowExchangeInstallationP,
dough10,
wonka7,
timerP,
'singularity',
],
seatIdentity:
allegedOptionsInviteAmount.quantity.seatIdentity,
seatDesc: 'holder',
Expand Down
6 changes: 3 additions & 3 deletions test/test-demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ const contractCoveredCallGolden = [
'++ bob.offerAliceOption starting',
'++ alice.acceptOptionDirectly starting',
'Pretend singularity never happens',
'alice invite xfer balance {"label":{"issuer":{},"description":"contract host"},"quantity":{"installation":{},"terms":[{"label":{"issuer":{},"description":"smackers"},"quantity":10},{"label":{"issuer":{},"description":"yoyodyne"},"quantity":7},{},"singularity"],"seatIdentity":{},"seatDesc":"holder"}}',
'verified invite xfer balance {"label":{"issuer":{},"description":"contract host"},"quantity":{"installation":{},"terms":[{"label":{"issuer":{},"description":"smackers"},"quantity":10},{"label":{"issuer":{},"description":"yoyodyne"},"quantity":7},{},"singularity"],"seatIdentity":{},"seatDesc":"holder"}}',
'alice invite xfer balance {"label":{"issuer":{},"description":"contract host"},"quantity":{"installation":{},"terms":[{},{"label":{"issuer":{},"description":"smackers"},"quantity":10},{"label":{"issuer":{},"description":"yoyodyne"},"quantity":7},{},"singularity"],"seatIdentity":{},"seatDesc":"holder"}}',
'verified invite xfer balance {"label":{"issuer":{},"description":"contract host"},"quantity":{"installation":{},"terms":[{},{"label":{"issuer":{},"description":"smackers"},"quantity":10},{"label":{"issuer":{},"description":"yoyodyne"},"quantity":7},{},"singularity"],"seatIdentity":{},"seatDesc":"holder"}}',
'alice option wins: {"label":{"issuer":{},"description":"yoyodyne"},"quantity":7} refs: null',
'bob option wins: {"label":{"issuer":{},"description":"smackers"},"quantity":10} refs: null',
'++ bob.offerAliceOption done',
Expand Down Expand Up @@ -193,7 +193,7 @@ const contractCoveredCallSaleGolden = [
'++ fred.acceptOptionOffer starting',
'Pretend singularity never happens',
'alice options sale wins: {"label":{"issuer":{},"description":"fins"},"quantity":55} refs: null',
'fred buys escrowed option wins: {"label":{"issuer":{},"description":"contract host"},"quantity":{"installation":{},"terms":[{"label":{"issuer":{},"description":"dough"},"quantity":10},{"label":{"issuer":{},"description":"wonka"},"quantity":7},{},"singularity"],"seatIdentity":{},"seatDesc":"holder"}} refs: null',
'fred buys escrowed option wins: {"label":{"issuer":{},"description":"contract host"},"quantity":{"installation":{},"terms":[{},{"label":{"issuer":{},"description":"dough"},"quantity":10},{"label":{"issuer":{},"description":"wonka"},"quantity":7},{},"singularity"],"seatIdentity":{},"seatDesc":"holder"}} refs: null',
'fred exercises option, buying stock wins: {"label":{"issuer":{},"description":"wonka"},"quantity":7} refs: null',
'bob option wins: {"label":{"issuer":{},"description":"dough"},"quantity":10} refs: null',
'++ alice.acceptOptionForFred done',
Expand Down

0 comments on commit 0497ccf

Please sign in to comment.