Skip to content

Commit a24124a

Browse files
committed
fix(upload-contract): make deterministic
1 parent 347a52b commit a24124a

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

lib/ag-solo/upload-contract.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ export default async function upload(basedir, args) {
5151
}
5252
}
5353

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' });
5755
const exit = makePromise();
5856
ws.on('open', async () => {
5957
try {
@@ -74,44 +72,46 @@ export default async function upload(basedir, args) {
7472
}
7573
});
7674

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`);
8287
}
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}`);
8693

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+
}
98105

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);
106107

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+
}
114113

114+
await Promise.all(uploadAP);
115115
console.log('Success! See home.uploads~.list()');
116116
ws.close();
117117
exit.res(0);

0 commit comments

Comments
 (0)