#!/usr/bin/env node /** * Simple Stratum Test Client to debug protocol issues */ const net = require('net'); class StratumDebugClient { constructor(host = '127.0.0.1', port = 3333) { this.host = host; this.port = port; this.socket = null; this.messageId = 1; } connect() { return new Promise((resolve, reject) => { this.socket = new net.Socket(); this.socket.connect(this.port, this.host, () => { console.log('✅ Connected to stratum server'); resolve(); }); this.socket.on('data', (data) => { console.log('📨 Received:', data.toString().trim()); }); this.socket.on('close', () => { console.log('🔌 Connection closed'); }); this.socket.on('error', (error) => { console.error(`❌ Connection error: ${error.message}`); reject(error); }); }); } sendMessage(method, params = [], id = null) { const message = { id: id || this.messageId++, method: method, params: params }; const jsonMessage = JSON.stringify(message) + '\n'; console.log('📤 Sending:', jsonMessage.trim()); this.socket.write(jsonMessage); } async test() { try { await this.connect(); // Test subscription console.log('\n=== Testing Subscription ==='); this.sendMessage('mining.subscribe', ['TestClient/1.0']); // Wait for response await new Promise(resolve => setTimeout(resolve, 2000)); // Test authorization console.log('\n=== Testing Authorization ==='); this.sendMessage('mining.authorize', ['worker1', 'x']); // Wait for response await new Promise(resolve => setTimeout(resolve, 2000)); console.log('\n=== Test Complete ==='); } catch (error) { console.error(`❌ Test error: ${error.message}`); } } } // Start test const client = new StratumDebugClient(); client.test().catch(error => { console.error(`❌ Failed to start test: ${error.message}`); process.exit(1); });