Skip to content

Commit

Permalink
fix(vats): don't give all of bankManager to 1 account
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed May 9, 2024
1 parent c11fecb commit d1f1630
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/vats/src/localchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import { AmountShape } from '@agoric/ertp';
const { Fail } = assert;

/**
* @import {BankManager} from './vat-bank.js';
* @import {BankManager, Bank} from './vat-bank.js';
* @import {ScopedBridgeManager} from './types.js';
*/

/** @import {TypedJson, ResponseTo} from '@agoric/cosmic-proto'; */

/**
* @typedef {{
* system: ScopedBridgeManager;
* bank: Bank;
* }} AccountPowers
*/

/**
* @typedef {{
* system: ScopedBridgeManager;
Expand All @@ -34,7 +41,7 @@ const prepareLocalChainAccount = zone =>
LocalChainAccountI,
/**
* @param {string} address
* @param {LocalChainPowers} powers
* @param {AccountPowers} powers
*/
(address, powers) => ({ address, ...powers, reserved: undefined }),
{
Expand All @@ -50,12 +57,11 @@ const prepareLocalChainAccount = zone =>
* @param {Payment} payment
*/
async deposit(payment) {
const { address, bankManager } = this.state;
const { bank } = this.state;

const allegedBrand = await E(payment).getAllegedBrand();
const bankAcct = E(bankManager).getBankForAddress(address);
const allegedPurse = E(bankAcct).getPurse(allegedBrand);
return E(allegedPurse).deposit(payment);
const purse = E(bank).getPurse(allegedBrand);
return E(purse).deposit(payment);
},
/**
* Execute a batch of transactions and return the responses. Use
Expand Down Expand Up @@ -118,7 +124,8 @@ const prepareLocalChain = (zone, makeAccount) =>
const address = await E(system).toBridge({
type: 'VLOCALCHAIN_ALLOCATE_ADDRESS',
});
return makeAccount(address, { system, bankManager });
const bank = await E(bankManager).getBankForAddress(address);
return makeAccount(address, { system, bank });
},
/**
* Make a single query to the local chain. Will reject with an error if
Expand Down

0 comments on commit d1f1630

Please sign in to comment.