1
1
/* global harden */
2
+ import { makeNotifierKit } from '@agoric/notifier' ;
2
3
import { E } from '@agoric/eventual-send' ;
3
4
import { getReplHandler } from './repl' ;
4
5
import { getCapTPHandler } from './captp' ;
@@ -7,34 +8,32 @@ import { getCapTPHandler } from './captp';
7
8
export function buildRootObject ( vatPowers ) {
8
9
const { D } = vatPowers ;
9
10
let commandDevice ;
10
- let provisioner ;
11
11
const channelIdToHandle = new Map ( ) ;
12
12
const channelHandleToId = new WeakMap ( ) ;
13
- const loaded = { } ;
14
- loaded . p = new Promise ( ( resolve , reject ) => {
15
- loaded . res = resolve ;
16
- loaded . rej = reject ;
17
- } ) ;
18
- harden ( loaded ) ;
13
+ let LOADING = harden ( [ 'agoric' , 'wallet' , 'local' ] ) ;
14
+ const {
15
+ notifier : loadingNotifier ,
16
+ updater : loadingUpdater ,
17
+ } = makeNotifierKit ( LOADING ) ;
18
+
19
19
const replObjects = {
20
- home : { LOADING : loaded . p } , // TODO: Remove
21
- agoric : { LOADING : loaded . p } ,
20
+ home : { LOADING } ,
21
+ agoric : { } ,
22
22
local : { } ,
23
23
} ;
24
- let isReady = false ;
25
- const readyForClient = { } ;
24
+
26
25
let exportedToCapTP = {
27
- LOADING : loaded . p ,
28
- READY : {
29
- resolve ( value ) {
30
- isReady = true ;
31
- readyForClient . res ( value ) ;
32
- } ,
33
- isReady ( ) {
34
- return isReady ;
35
- } ,
36
- } ,
26
+ loadingNotifier,
37
27
} ;
28
+ function doneLoading ( subsystems ) {
29
+ LOADING = LOADING . filter ( subsys => ! subsystems . includes ( subsys ) ) ;
30
+ loadingUpdater . updateState ( LOADING ) ;
31
+ if ( LOADING . length ) {
32
+ replObjects . home . LOADING = LOADING ;
33
+ } else {
34
+ delete replObjects . home . LOADING ;
35
+ }
36
+ }
38
37
39
38
const send = ( obj , channelHandles ) => {
40
39
// TODO: Make this sane by adding support for multicast to the commandDevice.
@@ -47,12 +46,6 @@ export function buildRootObject(vatPowers) {
47
46
}
48
47
} ;
49
48
50
- readyForClient . p = new Promise ( ( resolve , reject ) => {
51
- readyForClient . res = resolve ;
52
- readyForClient . rej = reject ;
53
- } ) ;
54
- harden ( readyForClient ) ;
55
-
56
49
const handler = { } ;
57
50
const registeredURLHandlers = new Map ( ) ;
58
51
@@ -68,65 +61,29 @@ export function buildRootObject(vatPowers) {
68
61
}
69
62
70
63
return harden ( {
71
- setCommandDevice ( d , ROLES ) {
64
+ setCommandDevice ( d ) {
72
65
commandDevice = d ;
73
- if ( ROLES . client ) {
74
- handler . readyForClient = ( ) => readyForClient . p ;
75
-
76
- const replHandler = getReplHandler ( replObjects , send , vatPowers ) ;
77
- registerURLHandler ( replHandler , '/private/repl' ) ;
78
-
79
- // Assign the captp handler.
80
- // TODO: Break this out into a separate vat.
81
- const captpHandler = getCapTPHandler (
82
- send ,
83
- // Harden only our exported objects.
84
- ( ) => harden ( exportedToCapTP ) ,
85
- { E, harden, ...vatPowers } ,
86
- ) ;
87
- registerURLHandler ( captpHandler , '/private/captp' ) ;
88
- }
89
66
90
- if ( ROLES . controller ) {
91
- handler . pleaseProvision = obj => {
92
- const { nickname, pubkey } = obj ;
93
- // FIXME: There's a race here. We return from the call
94
- // before the outbound messages have been committed to
95
- // a block. This means the provisioning-server must
96
- // retry transactions as they might have the wrong sequence
97
- // number.
98
- return E ( provisioner ) . pleaseProvision ( nickname , pubkey ) ;
99
- } ;
100
- handler . pleaseProvisionMany = obj => {
101
- const { applies } = obj ;
102
- return Promise . all (
103
- applies . map ( args =>
104
- // Emulate allSettled.
105
- E ( provisioner )
106
- . pleaseProvision ( ...args )
107
- . then (
108
- value => ( { status : 'fulfilled' , value } ) ,
109
- reason => ( { status : 'rejected' , reason } ) ,
110
- ) ,
111
- ) ,
112
- ) ;
113
- } ;
114
- }
67
+ const replHandler = getReplHandler ( replObjects , send , vatPowers ) ;
68
+ registerURLHandler ( replHandler , '/private/repl' ) ;
69
+
70
+ // Assign the captp handler.
71
+ // TODO: Break this out into a separate vat.
72
+ const captpHandler = getCapTPHandler (
73
+ send ,
74
+ // Harden only our exported objects.
75
+ ( ) => harden ( exportedToCapTP ) ,
76
+ { E, harden, ...vatPowers } ,
77
+ ) ;
78
+ registerURLHandler ( captpHandler , '/private/captp' ) ;
115
79
} ,
116
80
117
81
registerURLHandler,
118
82
registerAPIHandler : h => registerURLHandler ( h , '/api' ) ,
119
83
send,
120
-
121
- setProvisioner ( p ) {
122
- provisioner = p ;
123
- } ,
84
+ doneLoading,
124
85
125
86
setWallet ( wallet ) {
126
- // This must happen only after the local and agoric objects have been
127
- // installed in setPresences.
128
- // We're guaranteed that because the deployment script that installs
129
- // the wallet only runs after the chain has provisioned us.
130
87
exportedToCapTP = {
131
88
...exportedToCapTP ,
132
89
local : { ...exportedToCapTP . local , wallet } ,
@@ -142,23 +99,23 @@ export function buildRootObject(vatPowers) {
142
99
handyObjects = undefined ,
143
100
) {
144
101
exportedToCapTP = {
102
+ ...exportedToCapTP ,
145
103
...decentralObjects , // TODO: Remove; replaced by .agoric
146
104
...privateObjects , // TODO: Remove; replaced by .local
147
105
...handyObjects ,
148
- LOADING : loaded . p , // TODO: Remove; replaced by .agoric.LOADING
149
- agoric : { ...decentralObjects , LOADING : loaded . p } ,
150
- local : privateObjects ,
106
+ agoric : { ...decentralObjects } ,
107
+ local : { ...privateObjects } ,
151
108
} ;
152
109
153
110
// We need to mutate the repl subobjects instead of replacing them.
154
111
if ( privateObjects ) {
155
112
Object . assign ( replObjects . local , privateObjects ) ;
113
+ doneLoading ( [ 'local' ] ) ;
156
114
}
157
115
158
116
if ( decentralObjects ) {
159
- loaded . res ( 'chain bundle loaded' ) ;
160
117
Object . assign ( replObjects . agoric , decentralObjects ) ;
161
- delete replObjects . agoric . LOADING ;
118
+ doneLoading ( [ ' agoric' ] ) ;
162
119
}
163
120
164
121
// TODO: Remove; home object is deprecated.
@@ -169,7 +126,6 @@ export function buildRootObject(vatPowers) {
169
126
privateObjects ,
170
127
handyObjects ,
171
128
) ;
172
- delete replObjects . home . LOADING ;
173
129
}
174
130
} ,
175
131
@@ -240,6 +196,11 @@ export function buildRootObject(vatPowers) {
240
196
}
241
197
242
198
if ( dispatcher === 'onMessage' ) {
199
+ D ( commandDevice ) . sendResponse (
200
+ count ,
201
+ false ,
202
+ harden ( { type : 'doesNotUnderstand' , obj } ) ,
203
+ ) ;
243
204
throw Error ( `No handler for ${ url } ${ type } ` ) ;
244
205
}
245
206
D ( commandDevice ) . sendResponse ( count , false , harden ( true ) ) ;
0 commit comments