-
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
- Loading branch information
1 parent
ba75ed6
commit c6de9a0
Showing
6 changed files
with
196 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); | ||
}; |
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
// @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'; | ||
import { M } from '@endo/patterns'; | ||
|
||
/** | ||
* @import * as orchestration from '../types' | ||
* @import * as vatData from '@agoric/vat-data' | ||
*/ | ||
|
||
/** | ||
* @typedef {{ | ||
* hostConnectionId: orchestration.ConnectionId; | ||
* controllerConnectionId: orchestration.ConnectionId; | ||
* }} StakeAtomTerms | ||
*/ | ||
|
||
/** | ||
* | ||
* @param {ZCF<StakeAtomTerms>} zcf | ||
* @param {{ | ||
* orchestration: orchestration.Orchestration; | ||
* }} privateArgs | ||
* @param {vatData.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', | ||
M.interface('StakeAtomI', { | ||
createAccount: M.callWhen().returns(M.remotable('ChainAccount')), | ||
}), | ||
{ | ||
async createAccount() { | ||
return E(orchestration).createAccount( | ||
hostConnectionId, | ||
controllerConnectionId, | ||
); | ||
}, | ||
}, | ||
); | ||
|
||
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