@@ -51,9 +51,7 @@ export default async function upload(basedir, args) {
51
51
}
52
52
}
53
53
54
- const originurl = new URL ( '/' , wsurl ) ;
55
- originurl . protocol = 'https:' ;
56
- const ws = new WebSocket ( wsurl , { origin : originurl . href } ) ;
54
+ const ws = new WebSocket ( wsurl , { origin : 'http://127.0.0.1' } ) ;
57
55
const exit = makePromise ( ) ;
58
56
ws . on ( 'open' , async ( ) => {
59
57
try {
@@ -74,44 +72,46 @@ export default async function upload(basedir, args) {
74
72
}
75
73
} ) ;
76
74
77
- let bootC ;
78
- for ( ; ; ) {
79
- bootC = E . C ( bootstrap ( ) ) ;
80
- if ( ! ( await bootC . G . LOADING . P ) ) {
81
- break ;
75
+ // Wait for the chain to become ready.
76
+ let bootC = E . C ( bootstrap ( ) ) ;
77
+ console . log ( 'Chain loaded:' , await bootC . G . LOADING . P ) ;
78
+ // Take a new copy, since the contract targets should exist.
79
+ bootC = E . C ( bootstrap ( ) ) ;
80
+
81
+ const contractAP = [ ] ;
82
+ const names = [ ] ;
83
+ for ( const namePath of namePaths ) {
84
+ const match = namePath . match ( / ^ ( ( [ ^ \W - ] + ) - [ ^ = ] + ) = ( .+ ) $ / ) ;
85
+ if ( ! match ) {
86
+ throw Error ( `${ namePath } isn't TARGET-NAME=PATH` ) ;
82
87
}
83
- console . log ( `waiting for chain to become ready` ) ;
84
- await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
85
- }
88
+ const name = match [ 1 ] ;
89
+ const target = match [ 2 ] ;
90
+ const filepath = match [ 3 ] ;
91
+ const { source, moduleFormat } = await buildSourceBundle ( filepath ) ;
92
+ // console.log(`Uploading ${source}`);
86
93
87
- await Promise . all (
88
- namePaths . map ( async namePath => {
89
- const match = namePath . match ( / ^ ( ( [ ^ \W - ] + ) - [ ^ = ] + ) = ( . + ) $ / ) ;
90
- if ( ! match ) {
91
- throw Error ( ` ${ namePath } isn't TARGET-NAME=PATH` ) ;
92
- }
93
- const name = match [ 1 ] ;
94
- const target = match [ 2 ] ;
95
- const filepath = match [ 3 ] ;
96
- const { source , moduleFormat } = await buildSourceBundle ( filepath ) ;
97
- // console.log(`Uploading ${source}`);
94
+ const targetObj = await bootC . G [ target ] . P ;
95
+ if ( ! targetObj ) {
96
+ console . error (
97
+ `Contract installation target object ${ target } is not available for ${ name } ; skipping...` ,
98
+ ) ;
99
+ } else {
100
+ // Install the contract, then save it in home.uploads.
101
+ contractAP . push ( E ( targetObj ) . install ( source , moduleFormat ) ) ;
102
+ names . push ( name ) ;
103
+ }
104
+ }
98
105
99
- const targetObj = await bootC . G [ target ] . P ;
100
- if ( ! targetObj ) {
101
- console . error (
102
- `Contract installation target object ${ target } is not available for ${ name } ; skipping...` ,
103
- ) ;
104
- return null ;
105
- }
106
+ const contracts = await Promise . all ( contractAP ) ;
106
107
107
- // Install the contract, then save it in home.uploads.
108
- return bootC . G . uploads . M . set (
109
- name ,
110
- E ( targetObj ) . install ( source , moduleFormat ) ,
111
- ) . P ;
112
- } ) ,
113
- ) ;
108
+ const uploadsC = bootC . G . uploads ;
109
+ const uploadAP = [ ] ;
110
+ for ( let i = 0 ; i < contractAP . length ; i += 1 ) {
111
+ uploadAP . push ( uploadsC . M . set ( names [ i ] , contracts [ i ] ) . P ) ;
112
+ }
114
113
114
+ await Promise . all ( uploadAP ) ;
115
115
console . log ( 'Success! See home.uploads~.list()' ) ;
116
116
ws . close ( ) ;
117
117
exit . res ( 0 ) ;
0 commit comments