/
eth2near-relay.js
83 lines (80 loc) 路 2.63 KB
/
eth2near-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
const ProcessManager = require('pm2')
const { spawnProcess } = require('./helpers')
const {
EthOnNearClientContract,
Eth2NearRelay
} = require('rainbow-bridge-eth2near-block-relay')
const { nearAPI } = require('rainbow-bridge-utils')
const path = require('path')
class StartEth2NearRelayCommand {
static async execute ({
daemon,
nearNetworkId,
nearNodeUrl,
nearMasterAccount,
nearMasterSk,
nearClientAccount,
totalSubmitBlock,
gasPerTransaction,
ethNodeUrl,
metricsPort
}) {
if (daemon === 'true') {
ProcessManager.connect((err) => {
if (err) {
console.log(
'Unable to connect to the ProcessManager daemon! Please retry.'
)
return
}
spawnProcess('eth2near-relay', {
name: 'eth2near-relay',
script: path.join(__dirname, '../../index.js'),
interpreter: 'node',
error_file: '~/.rainbow/logs/eth2near-relay/err.log',
out_file: '~/.rainbow/logs/eth2near-relay/out.log',
args: [
'start', 'eth2near-relay',
'--near-network-id', nearNetworkId,
'--near-node-url', nearNodeUrl,
'--near-master-account', nearMasterAccount,
'--near-master-sk', nearMasterSk,
'--near-client-account', nearClientAccount,
'--eth-node-url', ethNodeUrl,
'--total-submit-block', totalSubmitBlock,
'--gas-per-transaction', gasPerTransaction,
'--daemon', 'false',
'--metrics-port', metricsPort
],
wait_ready: true,
kill_timeout: 60000,
logDateFormat: 'YYYY-MM-DD HH:mm:ss.SSS'
})
})
} else {
const keyStore = new nearAPI.keyStores.InMemoryKeyStore()
await keyStore.setKey(
nearNetworkId,
nearMasterAccount,
nearAPI.KeyPair.fromString(nearMasterSk)
)
const near = await nearAPI.connect({
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearMasterAccount,
keyStore
})
const relay = new Eth2NearRelay()
const clientContract = new EthOnNearClientContract(
new nearAPI.Account(near.connection, nearMasterAccount),
nearClientAccount
)
await clientContract.accessKeyInit()
console.log('Initializing eth2near-relay...', { ethNodeUrl, metricsPort })
relay.initialize(clientContract, { ethNodeUrl, totalSubmitBlock, gasPerTransaction, metricsPort, nearNetworkId })
console.log('Starting eth2near-relay...')
await relay.run()
}
}
}
exports.StartEth2NearRelayCommand = StartEth2NearRelayCommand