Skip to content

Commit 97053d1

Browse files
committed
wip: update
1 parent 608e6cd commit 97053d1

File tree

2 files changed

+62
-16
lines changed

2 files changed

+62
-16
lines changed

packages/neuron-wallet/src/controllers/perun.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import * as wire from "../utils/perun-wallet-wrapper/wire"
2222
import { PerunMessageReceiver } from '../services/perun/message-receiver'
2323
import { getConnection } from '../database/chain/connection'
2424
import PerunChannelInfoEntity from '../database/chain/entities/perun-channel-info'
25+
// import PerunChannelServiceRunner from '../services/perun/channel-service-runner'
2526

27+
// const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
2628
const defaultAddressEncoder: AddressEncoder = (add: Uint8Array | string) => {
2729
if (typeof add === 'string') {
2830
return bytes.bytify(add)
@@ -192,10 +194,14 @@ export default class PerunController {
192194
context
193195
}
194196
logger.info('PerunController: start-----PerunService-----')
195-
// start wallet-backend
196-
await PerunMessageReceiver.getInstance().start()
197197
// todo
198198
// start channel-service-runner
199+
// await PerunChannelServiceRunner.getInstance().start(context)
200+
// start wallet-backend
201+
await PerunMessageReceiver.getInstance().start()
202+
203+
// await sleep(5000)
204+
199205

200206
PerunRunnerStateSubject.next(this.runnerStatus)
201207

@@ -213,6 +219,7 @@ export default class PerunController {
213219
PerunRunnerStateSubject.next(this.runnerStatus)
214220
// todo
215221
// stop channel-service-runner
222+
// PerunChannelServiceRunner.getInstance().stop();
216223
// stop wallet-backend
217224
PerunMessageReceiver.getInstance().stop();
218225
return {

packages/neuron-wallet/src/services/perun/channel-service-runner.ts

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import generateConfigFiles, { ConfigFileOptions } from './configFiles'
55
import path from 'path'
66
import SettingsService from '../settings'
77
import fs from 'fs'
8+
import PerunController from '../../controllers/perun'
89

910
const { app } = env
1011
const platform = (): string => {
@@ -20,7 +21,9 @@ const platform = (): string => {
2021
}
2122
}
2223
const binaryPath = (): string => {
23-
return app.isPackaged ? path.join(path.dirname(app.getAppPath()), '..', './bin') : path.join(__dirname, '../../bin')
24+
return app.isPackaged
25+
? path.join(path.dirname(app.getAppPath()), '..', './bin')
26+
: path.join(__dirname, '../../../bin')
2427
}
2528
const channelServiceRunnerBinary = (): string => {
2629
const binary = app.isPackaged ? path.resolve(binaryPath(), './channel-service-runner') : path.resolve(binaryPath(), `./${platform()}`, './channel-service-runner')
@@ -57,7 +60,7 @@ export default class PerunChannelServiceRunner {
5760
await this.stop()
5861
}
5962

60-
const { config, contractCellDeps, systemScripts } = generateConfigFiles(opt)
63+
const { config } = generateConfigFiles(opt) // , contractCellDeps, systemScripts
6164

6265
const perunFolderPath = SettingsService.getInstance().getPeurnDataFolderPath();
6366
const pathWithNetwork = path.join(perunFolderPath, opt.network);
@@ -66,34 +69,70 @@ export default class PerunChannelServiceRunner {
6669
const file_config_path = path.join(pathWithNetwork, 'config.json');
6770
fs.writeFileSync(file_config_path, JSON.stringify(config, null, 2));
6871

69-
const file_contractCellDeps_path = path.join(pathWithNetwork, 'contracts_cell_deps.json');
70-
fs.writeFileSync(file_contractCellDeps_path, JSON.stringify(contractCellDeps, null, 2));
72+
// const file_contractCellDeps_path = path.join(pathWithNetwork, 'contracts_cell_deps.json');
73+
// fs.writeFileSync(file_contractCellDeps_path, JSON.stringify(contractCellDeps, null, 2));
74+
75+
// const file_systemScripts_path = path.join(pathWithNetwork, 'system_scripts.json');
76+
// fs.writeFileSync(file_systemScripts_path, JSON.stringify(systemScripts, null, 2));
77+
78+
79+
console.log(channelServiceRunnerBinary(), file_config_path)
7180

72-
const file_systemScripts_path = path.join(pathWithNetwork, 'system_scripts.json');
73-
fs.writeFileSync(file_systemScripts_path, JSON.stringify(systemScripts, null, 2));
74-
7581
const scrProcess = spawn(channelServiceRunnerBinary(), [
7682
// --config config.json
7783
'--config',
78-
`"${file_config_path}"`,
84+
`${file_config_path}`,
7985
// --system_scripts default_scripts.json
80-
'--system_scripts',
81-
`"${file_systemScripts_path}"`,
86+
// '--system_scripts',
87+
// `"${file_systemScripts_path}"`,
8288
// --migration_data contracts_cell_deps.json
83-
'--migration_data',
84-
`"${file_contractCellDeps_path}"`,
89+
// '--migration_data',
90+
// `"${file_contractCellDeps_path}"`,
8591
])
8692

87-
scrProcess.stderr?.on('data', data => {
88-
logger.error('PerunChannelServiceRunner:\t fail:', data.toString())
93+
scrProcess?.on('spawn', () => {
94+
logger.info(`PerunChannelServiceRunner spawn`)
95+
// this.logStream?.write(data)
96+
})
97+
98+
scrProcess.stderr.on('data', data => {
99+
logger.error(`PerunChannelServiceRunner stderr: ${data}`)
100+
// this.logStream?.write(data)
101+
})
102+
103+
scrProcess.stdout.on('data', data => {
104+
logger.info(`PerunChannelServiceRunner stdout: ${data}`)
105+
// this.logStream?.write(data)
106+
})
107+
108+
scrProcess.on('message', data => {
109+
logger.info(`PerunChannelServiceRunner message: ${data}`)
110+
// this.logStream?.write(data)
89111
})
90112

113+
scrProcess.on('exit', data => {
114+
logger.info(`PerunChannelServiceRunner exit: ${data}`)
115+
// this.logStream?.write(data)
116+
})
117+
118+
91119
scrProcess.on("error", error => {
92120
logger.error('PerunChannelServiceRunner:\t fail:', error)
121+
this.runnerProcess?.kill()
122+
this.runnerProcess = undefined
123+
PerunController.emiter.emit("perun-service", {
124+
runner: "channel-service-runner",
125+
type: 'stop',
126+
message: error.message
127+
})
93128
})
94129

95130
scrProcess.once("close", () => {
96131
logger.info('PerunChannelServiceRunner:\t closed')
132+
PerunController.emiter.emit("perun-service", {
133+
runner: "channel-service-runner",
134+
type: 'stop'
135+
})
97136
this.runnerProcess = undefined;
98137
})
99138

0 commit comments

Comments
 (0)