/
near2eth-relay.js
92 lines (90 loc) 路 2.97 KB
/
near2eth-relay.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const ProcessManager = require('pm2')
const { spawnProcess } = require('./helpers')
const { Near2EthRelay } = require('rainbow-bridge-near2eth-block-relay')
const path = require('path')
class StartNear2EthRelayCommand {
static async execute ({
daemon,
nearNodeUrl,
nearNetworkId,
ethNodeUrl,
ethMasterSk,
ethClientArtifactPath,
ethClientAddress,
ethGasMultiplier,
ethUseEip1559,
near2ethRelayMinDelay,
near2ethRelayMaxDelay,
near2ethRelayErrorDelay,
near2ethRelayBlockSelectDuration,
near2ethRelayNextBlockSelectDelayMs,
near2ethRelayAfterSubmitDelayMs,
metricsPort,
logVerbose
}) {
if (daemon === 'true') {
ProcessManager.connect((err) => {
if (err) {
console.log(
'Unable to connect to the ProcessManager daemon! Please retry.'
)
return
}
spawnProcess('near2eth-relay', {
name: 'near2eth-relay',
script: path.join(__dirname, '../../index.js'),
interpreter: 'node',
error_file: '~/.rainbow/logs/near2eth-relay/err.log',
out_file: '~/.rainbow/logs/near2eth-relay/out.log',
args: [
'start', 'near2eth-relay',
'--near-node-url', nearNodeUrl,
'--near-network-id', nearNetworkId,
'--eth-node-url', ethNodeUrl,
'--eth-master-sk', ethMasterSk,
'--eth-client-artifact-path', ethClientArtifactPath,
'--eth-client-address', ethClientAddress,
'--eth-gas-multiplier', ethGasMultiplier,
'--eth-use-eip-1559', ethUseEip1559,
'--near2eth-relay-min-delay', near2ethRelayMinDelay,
'--near2eth-relay-max-delay', near2ethRelayMaxDelay,
'--near2eth-relay-error-delay', near2ethRelayErrorDelay,
'--near2eth-relay-block-select-duration', near2ethRelayBlockSelectDuration,
'--near2eth-relay-next-block-select-delay-ms', near2ethRelayNextBlockSelectDelayMs,
'--near2eth-relay-after-submit-delay-ms', near2ethRelayAfterSubmitDelayMs,
'--daemon', 'false',
'--metrics-port', metricsPort,
'--log-verbose', logVerbose
],
wait_ready: true,
kill_timeout: 60000,
logDateFormat: 'YYYY-MM-DD HH:mm:ss.SSS'
})
})
} else {
const relay = new Near2EthRelay()
await relay.initialize({
nearNodeUrl,
nearNetworkId,
ethNodeUrl,
ethMasterSk,
ethClientArtifactPath,
ethClientAddress,
ethGasMultiplier,
metricsPort
})
await relay.run({
near2ethRelayMinDelay,
near2ethRelayMaxDelay,
near2ethRelayErrorDelay,
near2ethRelayBlockSelectDuration,
near2ethRelayNextBlockSelectDelayMs,
near2ethRelayAfterSubmitDelayMs,
ethGasMultiplier,
ethUseEip1559,
logVerbose
})
}
}
}
exports.StartNear2EthRelayCommand = StartNear2EthRelayCommand