From 9a8bd5c8637b44445edbc29bc3964b90470e2205 Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Wed, 11 Dec 2024 17:54:50 -0400 Subject: [PATCH] Test 1 --- lib/hsm-runner.js | 60 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/hsm-runner.js b/lib/hsm-runner.js index 8d42d11b..c6324e55 100644 --- a/lib/hsm-runner.js +++ b/lib/hsm-runner.js @@ -209,13 +209,11 @@ const spawnProcessVersion5 = async (serverPath, port, keyPath, latestBlockHash, `-p8888 > /bundle/tcpsigner.log 2>&1 &` ]; - // const tcpsignerCommand = `${serverPath}/tcpsigner -p${port} --c=${latestBlockHash} --difficulty=0x${difficultyTarget.toString(16).padStart(2, '0')} -k keys.json -p8888 > /bundle/tcpsigner.log 2>&1 &`; - console.log('tcpsignerCommand: ', tcpsignerCommand) childProcess.spawn(tcpsignerCommand, args, { stdio: 'inherit', shell: true }); - await wait(2000); + await portUtils.waitForPort('localhost', port); const tcpsignerManagerArgs = [ `-b0.0.0.0`, @@ -273,7 +271,7 @@ HSMRunner.prototype.spawnProcess = function() { } } -HSMRunner.prototype.start = function() { +HSMRunner.prototype.start = async function() { if (this.isRunning()) { throw "HSM already started"; } @@ -294,39 +292,41 @@ HSMRunner.prototype.start = function() { this.port = selectedPorts[0]; } - this.process = this.spawnProcess(); - if (this.process.stdout) { - if (this.options.stdout != null) { - this.process.stdout.pipe(this.options.stdout); - } else { - this.process.stdout.pipe(devnull()); + this.spawnProcess().then(process => { + this.process = process; + if (this.process.stdout) { + if (this.options.stdout != null) { + this.process.stdout.pipe(this.options.stdout); + } else { + this.process.stdout.pipe(devnull()); + } } - } - if (this.process.stderr) { - if (this.options.stderr != null) { - this.process.stderr.pipe(this.options.stderr); - } else { - this.process.stderr.pipe(devnull()); + if (this.process.stderr) { + if (this.options.stderr != null) { + this.process.stderr.pipe(this.options.stderr); + } else { + this.process.stderr.pipe(devnull()); + } } - } - - this.running = false; - this.process.on('exit', () => { this.running = false; - }); - this.client = HsmClient.getClient(this.options.host, this.port); + this.process.on('exit', () => { + this.running = false; + }); - return executeWithRetries( - () => { - return this.getPublicKey(); - }, - 10, - 1000).then((r) => { - this.running = true; - return r; + this.client = HsmClient.getClient(this.options.host, this.port); + + return executeWithRetries( + () => { + return this.getPublicKey(); + }, + 10, + 1000).then((r) => { + this.running = true; + return r; + }); }); }); };