Skip to content

Commit

Permalink
fix websocket connection
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhson1085 committed Nov 29, 2018
1 parent 2c74659 commit 76ef9a3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion apis/candidates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express')
const axios = require('axios')
const router = express.Router()
const db = require('../models/mongodb')
const web3 = require('../models/blockchain/web3')
const web3 = require('../models/blockchain/web3rpc')
const validator = require('../models/blockchain/validator')
const HDWalletProvider = require('truffle-hdwallet-provider')
const PrivateKeyProvider = require('truffle-privatekey-provider')
Expand Down
2 changes: 1 addition & 1 deletion crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const validator = require('./models/blockchain/validator')
const blockSigner = require('./models/blockchain/blockSigner')
const web3 = require('./models/blockchain/web3')
const web3 = require('./models/blockchain/web3ws')
const config = require('config')
const db = require('./models/mongodb')
const EventEmitter = require('events').EventEmitter
Expand Down
2 changes: 1 addition & 1 deletion models/blockchain/blockSigner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const BlockSignerABI = require('../../build/contracts/BlockSigner')
const web3 = require('./web3')
const web3 = require('./web3ws')
const config = require('config')
const blockSigner = new web3.eth.Contract(BlockSignerABI.abi, config.get('blockchain.blockSignerAddress'))

Expand Down
2 changes: 1 addition & 1 deletion models/blockchain/validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const ValidatorABI = require('../../build/contracts/TomoValidator')
const web3 = require('./web3')
const web3 = require('./web3ws')
const config = require('config')
const validator = new web3.eth.Contract(ValidatorABI.abi, config.get('blockchain.validatorAddress'))

Expand Down
21 changes: 0 additions & 21 deletions models/blockchain/web3.js

This file was deleted.

18 changes: 18 additions & 0 deletions models/blockchain/web3ws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const Web3 = require('web3')
const config = require('config')

const provider = new Web3.providers.WebsocketProvider(config.get('blockchain.ws'))
const web3 = new Web3(provider)

const restart = function (e) {
console.error('Connection error', e)
console.error('Restart process')
process.exit(1)
}

provider.on('error', (e) => restart(e))
provider.on('end', (e) => restart(e))

module.exports = web3

0 comments on commit 76ef9a3

Please sign in to comment.