create-mn-app 0.3.15 → 0.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mn-app",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "description": "Create Midnight Network applications with zero configuration",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -8,7 +8,7 @@
8
8
  "scripts": {
9
9
  "compile": "compact compile contracts/hello-world.compact contracts/managed/hello-world",
10
10
  "build": "npx tsc --noEmit || true",
11
- "setup": "docker compose up -d && echo 'Waiting for proof server...' && sleep 5 && npm run compile && npm run deploy",
11
+ "setup": "docker compose up -d && npm run compile && npm run deploy",
12
12
  "deploy": "npx tsx src/deploy.ts",
13
13
  "cli": "npx tsx src/cli.ts",
14
14
  "check-balance": "npx tsx src/check-balance.ts",
@@ -43,6 +43,27 @@ const CONFIG = {
43
43
  faucetUrl: 'https://faucet.preprod.midnight.network/',
44
44
  };
45
45
 
46
+ // ─── Proof Server Health Check ─────────────────────────────────────────────────
47
+
48
+ async function waitForProofServer(maxAttempts = 30, delayMs = 2000): Promise<boolean> {
49
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
50
+ try {
51
+ const response = await fetch(`${CONFIG.proofServer}/health`, {
52
+ method: 'GET',
53
+ signal: AbortSignal.timeout(3000),
54
+ });
55
+ if (response.ok) return true;
56
+ } catch {
57
+ // Server not ready yet
58
+ }
59
+ if (attempt < maxAttempts) {
60
+ process.stdout.write(`\r Waiting for proof server... (${attempt}/${maxAttempts}) `);
61
+ await new Promise((r) => setTimeout(r, delayMs));
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+
46
67
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
47
68
  const zkConfigPath = path.resolve(__dirname, '..', 'contracts', 'managed', 'hello-world');
48
69
 
@@ -280,6 +301,31 @@ async function main() {
280
301
 
281
302
  // 4. Deploy contract
282
303
  console.log('─── Step 4: Deploy Contract ────────────────────────────────────\n');
304
+
305
+ // Check proof server is running
306
+ console.log(' Checking proof server...');
307
+ const proofServerReady = await waitForProofServer();
308
+ if (!proofServerReady) {
309
+ console.log('\n ❌ Proof server not responding\n');
310
+ console.log(' The proof server is required to generate zk-proofs for transactions.\n');
311
+ console.log(' ┌─ Start it with ──────────────────────────────────────────────┐');
312
+ console.log(' │ │');
313
+ console.log(' │ $ docker compose up -d │');
314
+ console.log(' │ │');
315
+ console.log(' │ Then retry: $ npm run deploy │');
316
+ console.log(' │ │');
317
+ console.log(' └──────────────────────────────────────────────────────────────┘\n');
318
+
319
+ // Save seed for retry
320
+ const partialInfo = { seed, address, network: 'preprod', status: 'proof_server_unavailable' };
321
+ fs.writeFileSync('deployment.json', JSON.stringify(partialInfo, null, 2));
322
+ console.log(' Wallet saved to deployment.json\n');
323
+
324
+ await walletCtx.wallet.stop();
325
+ process.exit(1);
326
+ }
327
+ process.stdout.write('\r Proof server ready! \n');
328
+
283
329
  console.log(' Setting up providers...');
284
330
  const providers = await createProviders(walletCtx);
285
331
 
@@ -300,9 +346,33 @@ async function main() {
300
346
  break; // Success - exit retry loop
301
347
  } catch (err: any) {
302
348
  const errMsg = err?.message || err?.toString() || '';
349
+ const errCause = err?.cause?.message || err?.cause?.toString() || '';
350
+ const fullError = `${errMsg} ${errCause}`;
351
+
352
+ // Check for proof server errors first
353
+ if (fullError.includes('Failed to connect to Proof Server') ||
354
+ fullError.includes('Failed to prove') ||
355
+ fullError.includes('127.0.0.1:6300')) {
356
+ console.log(' ❌ Proof server error\n');
357
+ console.log(' The proof server may have stopped or crashed.\n');
358
+ console.log(' ┌─ Fix ────────────────────────────────────────────────────────┐');
359
+ console.log(' │ │');
360
+ console.log(' │ 1. Check if running: $ docker ps │');
361
+ console.log(' │ 2. Restart: $ docker compose up -d │');
362
+ console.log(' │ 3. Retry: $ npm run deploy │');
363
+ console.log(' │ │');
364
+ console.log(' └──────────────────────────────────────────────────────────────┘\n');
365
+
366
+ const partialInfo = { seed, address, network: 'preprod', status: 'proof_server_error' };
367
+ fs.writeFileSync('deployment.json', JSON.stringify(partialInfo, null, 2));
368
+ console.log(' Wallet saved to deployment.json\n');
369
+
370
+ await walletCtx.wallet.stop();
371
+ process.exit(1);
372
+ }
303
373
 
304
- // Check if it's a DUST-related error
305
- if (errMsg.includes('Not enough Dust') || errMsg.includes('Wallet.Transacting')) {
374
+ // Check if it's a DUST-related error (must check "Not enough Dust" specifically)
375
+ if (fullError.includes('Not enough Dust')) {
306
376
  // Get current DUST balance
307
377
  const currentState = await Rx.firstValueFrom(walletCtx.wallet.state().pipe(Rx.filter((s) => s.isSynced)));
308
378
  const dustBalance = currentState.dust.walletBalance(new Date());