-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orchestration): add stakeAtom example contract
- refs #9042
- Loading branch information
1 parent
4601a1a
commit 1b6090b
Showing
6 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
|
||
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */ | ||
export const defaultProposalBuilder = async ( | ||
{ publishRef, install }, | ||
options = {}, | ||
) => { | ||
const { | ||
hostConnectionId = 'connection-1', | ||
controllerConnectionId = 'connection-0', | ||
} = options; | ||
return harden({ | ||
sourceSpec: '@agoric/orchestration/src/proposals/start-stakeAtom.js', | ||
getManifestCall: [ | ||
'getManifestForStakeAtom', | ||
{ | ||
installKeys: { | ||
stakeAtom: publishRef( | ||
install( | ||
'@agoric/orchestration/src/contracts/stakeAtom.contract.js', | ||
), | ||
), | ||
}, | ||
hostConnectionId, | ||
controllerConnectionId, | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
export default async (homeP, endowments) => { | ||
const { writeCoreProposal } = await makeHelpers(homeP, endowments); | ||
await writeCoreProposal('start-stakeAtom', defaultProposalBuilder); | ||
}; |
44 changes: 44 additions & 0 deletions
44
packages/orchestration/src/contracts/stakeAtom.contract.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// @ts-check | ||
/** | ||
* @file Example contract that uses orchestration | ||
*/ | ||
|
||
import { makeDurableZone } from '@agoric/zone/durable.js'; | ||
import { V as E } from '@agoric/vat-data/vow.js'; | ||
|
||
/** | ||
* @typedef {{ | ||
* hostConnectionId: import('../types').ConnectionId; | ||
* controllerConnectionId: import('../types').ConnectionId; | ||
* }} StakeAtomTerms | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {ZCF<StakeAtomTerms>} zcf | ||
* @param {{ | ||
* orchestration: import('@agoric/vats/src/orchestration').Orchestration; | ||
* }} privateArgs | ||
* @param {import('@agoric/vat-data').Baggage} baggage | ||
*/ | ||
export const start = async (zcf, privateArgs, baggage) => { | ||
const { hostConnectionId, controllerConnectionId } = zcf.getTerms(); | ||
const { orchestration } = privateArgs; | ||
|
||
const zone = makeDurableZone(baggage); | ||
|
||
const publicFacet = zone.exo('StakeAtom', undefined, { | ||
/** | ||
* @param {Port} [port] if the user has a bound port and wants to reuse it | ||
*/ | ||
async createAccount(port) { | ||
return E(orchestration).createAccount( | ||
hostConnectionId, | ||
controllerConnectionId, | ||
port, | ||
); | ||
}, | ||
}); | ||
|
||
return { publicFacet }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// @ts-check | ||
import { makeTracer } from '@agoric/internal'; | ||
import { E } from '@endo/far'; | ||
|
||
const trace = makeTracer('StartStakeAtom', true); | ||
|
||
/** | ||
* @param {BootstrapPowers & { installation: {consume: {stakeAtom: Installation<import('../contracts/stakeAtom.contract.js').start>}}}} powers | ||
* @param {{options: import('../contracts/stakeAtom.contract.js').StakeAtomTerms}} options | ||
*/ | ||
export const startStakeAtom = async ( | ||
{ | ||
consume: { orchestration, startUpgradable }, | ||
installation: { | ||
consume: { stakeAtom }, | ||
}, | ||
instance: { | ||
produce: { stakeAtom: produceInstance }, | ||
}, | ||
}, | ||
{ options: { hostConnectionId, controllerConnectionId } }, | ||
) => { | ||
trace('startStakeAtom', { hostConnectionId, controllerConnectionId }); | ||
await null; | ||
|
||
/** @type {StartUpgradableOpts<import('../contracts/stakeAtom.contract.js').start>} */ | ||
const startOpts = { | ||
label: 'stakeAtom', | ||
installation: stakeAtom, | ||
terms: { | ||
hostConnectionId, | ||
controllerConnectionId, | ||
}, | ||
privateArgs: { | ||
orchestration: await orchestration, | ||
}, | ||
}; | ||
|
||
const { instance } = await E(startUpgradable)(startOpts); | ||
produceInstance.resolve(instance); | ||
}; | ||
harden(startStakeAtom); | ||
|
||
export const getManifestForStakeAtom = ( | ||
{ restoreRef }, | ||
{ installKeys, ...options }, | ||
) => { | ||
return { | ||
manifest: { | ||
[startStakeAtom.name]: { | ||
consume: { | ||
orchestration: true, | ||
startUpgradable: true, | ||
}, | ||
installation: { | ||
consume: { stakeAtom: true }, | ||
}, | ||
instance: { | ||
produce: { stakeAtom: true }, | ||
}, | ||
}, | ||
}, | ||
installations: { | ||
stakeAtom: restoreRef(installKeys.stakeAtom), | ||
}, | ||
options, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters