-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(bootstrap): make the bridge handler for provisioning durable
Refs: #10425
- Loading branch information
1 parent
0fa2d27
commit 6be81d7
Showing
3 changed files
with
117 additions
and
53 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
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,53 @@ | ||
import { prepareExoClass } from '@agoric/vat-data'; | ||
import { Fail } from '@endo/errors'; | ||
import { E } from '@endo/far'; | ||
import { BridgeHandlerI } from './bridge.js'; | ||
import { PowerFlags } from './walletFlags.js'; | ||
|
||
/** | ||
* @param {import('@agoric/store').MapStore} baggage | ||
*/ | ||
export const prepareProvisionBridgeHandler = baggage => { | ||
const makeProvisionBridgeHandler = prepareExoClass( | ||
baggage, | ||
'provisioningHandler', | ||
BridgeHandlerI, | ||
(provisioning, provisionWalletBridgeManager) => ({ | ||
provisioning, | ||
provisionWalletBridgeManager, | ||
}), | ||
{ | ||
async fromBridge(obj) { | ||
const { provisionWalletBridgeManager, provisioning } = this.state; | ||
switch (obj.type) { | ||
case 'PLEASE_PROVISION': { | ||
const { nickname, address, powerFlags: rawPowerFlags } = obj; | ||
const powerFlags = rawPowerFlags || []; | ||
let provisionP; | ||
if (powerFlags.includes(PowerFlags.SMART_WALLET)) { | ||
// Only provision a smart wallet. | ||
provisionP = E(provisionWalletBridgeManager).fromBridge(obj); | ||
} else { | ||
// Provision a mailbox and REPL. | ||
provisionP = E(provisioning).pleaseProvision( | ||
nickname, | ||
address, | ||
powerFlags, | ||
); | ||
} | ||
return provisionP | ||
.catch(e => | ||
console.error(`Error provisioning ${nickname} ${address}:`, e), | ||
) | ||
.then(_ => {}); | ||
} | ||
default: { | ||
throw Fail`Unrecognized request ${obj.type}`; | ||
} | ||
} | ||
}, | ||
}, | ||
); | ||
|
||
return makeProvisionBridgeHandler; | ||
}; |