Skip to content

Commit

Permalink
fix: ensure unique (but fake) addresses for sim-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Apr 10, 2021
1 parent a27393f commit 1a5f5c0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
40 changes: 26 additions & 14 deletions packages/cosmic-swingset/lib/ag-solo/vats/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,19 @@ export function buildRootObject(vatPowers, vatParameters) {
// Create a name hub for this address.
const {
nameHub: myAddressNameHub,
nameAdmin: myAddressNameAdmin,
nameAdmin: rawMyAddressNameAdmin,
} = makeNameHubKit();
// Register it with the namesByAddress hub.
namesByAddressAdmin.update(address, myAddressNameHub);

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

const bundle = harden({
...additionalPowers,
agoricNames,
Expand All @@ -417,12 +425,7 @@ export function buildRootObject(vatPowers, vatParameters) {
contractHost,
faucet,
ibcport,
myAddressNameAdmin: {
...myAddressNameAdmin,
getMyAddress() {
return address;
},
},
myAddressNameAdmin,
namesByAddress,
priceAuthority,
registrar: registry,
Expand Down Expand Up @@ -666,21 +669,30 @@ export function buildRootObject(vatPowers, vatParameters) {
// Allow some hardcoded client address connections into the chain.
// This is necessary for fake-chain, which does not have Cosmos SDK
// transactions to provision its client.
let nonce = 0;
const demoProvider = Far('demoProvider', {
// build a chain-side bundle for a client.
async getDemoBundle(nickname) {
nonce += 1;
if (giveMeAllTheAgoricPowers) {
// NOTE: This is a special exception to the security model,
// to give capabilities to all clients (since we are running
// locally with the `--give-me-all-the-agoric-powers` flag).
return chainBundler.createUserBundle(nickname, 'demo', [
'agoric.agoricNamesAdmin',
'agoric.priceAuthorityAdmin',
'agoric.treasuryCreator',
'agoric.vattp',
]);
return chainBundler.createUserBundle(
nickname,
`agoric1admin${nonce}`,
[
'agoric.agoricNamesAdmin',
'agoric.priceAuthorityAdmin',
'agoric.treasuryCreator',
'agoric.vattp',
],
);
}
return chainBundler.createUserBundle(nickname, 'demo');
return chainBundler.createUserBundle(
nickname,
`agoric1user${nonce}`,
);
},
});
await Promise.all(
Expand Down
4 changes: 4 additions & 0 deletions packages/cosmic-swingset/lib/ag-solo/vats/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
* outstanding reserved promise (if any).
*/

/**
* @typedef {NameAdmin & { getMyAddress(): string }} MyAddressNameAdmin
*/

/**
* @typedef {Object} NameHubKit A kit of a NameHub and its corresponding
* NameAdmin.
Expand Down

0 comments on commit 1a5f5c0

Please sign in to comment.