Skip to content

Commit

Permalink
feat(vats): agoricNames, namesByAddress, myAddressNameAdmin
Browse files Browse the repository at this point in the history
here's hoping for a test a la:

```
command[2] E(home.myAddressNameAdmin).getMyAddress()
history[2] "sim-chain-client"
```
  • Loading branch information
dckc authored and michaelfig committed Jan 16, 2022
1 parent f09eb66 commit 4535c8d
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions packages/vats/src/bootstrap-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { E, Far } from '@agoric/far';
import { AssetKind } from '@agoric/ertp';
import { makeNotifierKit } from '@agoric/notifier';
import { makeNameHubKit } from './nameHub';

const { entries, fromEntries } = Object;

Expand Down Expand Up @@ -32,6 +33,7 @@ export const bootstrapManifest = harden({
makeBoard: {
workspace: { vatAdminSvc: true, client: true },
},
makeAddressNameHubs: { workspace: true },
});

/**
Expand Down Expand Up @@ -96,11 +98,46 @@ const makeBoard = async ({ workspace: { vatAdminSvc, client } }) => {
return E(client).assignBundle({ board: _addr => board });
};

/* TODO
agoricNames,
namesByAddress,
myAddressNameAdmin,
/**
* @param {{ workspace: Record<string, unknown> }} powers
*/
const makeAddressNameHubs = async ({ workspace }) => {
const {
nameHub: agoricNames,
nameAdmin: agoricNamesAdmin,
} = makeNameHubKit();
workspace.agoricNamesAdmin = agoricNamesAdmin;

const {
nameHub: namesByAddress,
nameAdmin: namesByAddressAdmin,
} = makeNameHubKit();

const perAddress = address => {
// Create a name hub for this address.
const {
nameHub: myAddressNameHub,
nameAdmin: rawMyAddressNameAdmin,
} = makeNameHubKit();
// Register it with the namesByAddress hub.
namesByAddressAdmin.update(address, myAddressNameHub);

/** @type {MyAddressNameAdmin} */
const myAddressNameAdmin = Far('myAddressNameAdmin', {
...rawMyAddressNameAdmin,
getMyAddress: () => address,
});
return myAddressNameAdmin;
};

/* @ts-ignore TODO: cast client? */
return E(workspace.client).assignBundle({
agoricNames: _ => agoricNames,
namesByAddress: _ => namesByAddress,
myAddressNameAdmin: perAddress,
});
};

const callProperties = (obj, ...args) =>
fromEntries(entries(obj).map(([k, fn]) => [k, fn(...args)]));

Expand Down Expand Up @@ -150,12 +187,14 @@ harden({
makeVatAdminService,
buildZoe,
makeBoard,
makeAddressNameHubs,
installClientEgress,
});
export {
connectVattpWithMailbox,
makeVatAdminService,
buildZoe,
makeBoard,
makeAddressNameHubs,
installClientEgress,
};

0 comments on commit 4535c8d

Please sign in to comment.