aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-02-13 19:35:40 -0800
committerAdam Soltys <[email protected]>2018-02-13 19:35:40 -0800
commit7e14da4e949a06da92b8b67024b2ef813512236f (patch)
tree93165fab7968197961bc77353ada789edbbdfc7c /index.js
parentd41cd218ff1ebab07f2bf8e84ffa0ca7deeb1a04 (diff)
downloadcoinos-server-7e14da4e949a06da92b8b67024b2ef813512236f.tar.gz
coinos-server-7e14da4e949a06da92b8b67024b2ef813512236f.zip
read from zmq and use socket.io instead of deepstream
Diffstat (limited to 'index.js')
-rw-r--r--index.js38
1 files changed, 33 insertions, 5 deletions
diff --git a/index.js b/index.js
index 0aa5038e..cc40fe3a 100644
--- a/index.js
+++ b/index.js
@@ -12,8 +12,9 @@ import grpc from 'grpc'
import passport from './passport'
import jwt from 'jsonwebtoken'
import bcrypt from 'bcrypt'
-import deepstream from 'deepstream.io-client-js'
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express'
+import zmq from 'zmq'
+
dotenv.config()
const l = console.log
@@ -28,6 +29,34 @@ const l = console.log
app.use(compression())
app.use(passport.initialize())
+ app.use((req, res, next) => {
+ res.header('Access-Control-Allow-Origin', 'http://localhost:8085')
+ res.header('Access-Control-Allow-Credentials', true)
+ res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
+ res.header('Access-Control-Allow-Headers', 'Origin,X-Requested-With,Content-Type,Accept,content-type,application/json,Authorization')
+ next()
+ })
+
+ const server = require('http').createServer(app)
+ const io = require('socket.io').listen(server)
+ io.origins('http://localhost:8085')
+
+ let zmqSock = zmq.socket('sub')
+ zmqSock.connect('tcp://127.0.0.1:18503')
+ zmqSock.subscribe('rawblock')
+ zmqSock.subscribe('rawtx')
+
+ zmqSock.on('message', (topic, message, sequence) => {
+ topic = topic.toString('utf8')
+ message = message.toString('hex')
+
+ switch (topic) {
+ case 'rawtx': {
+ io.emit('tx', message)
+ }
+ }
+ })
+
const restClient = ba.restfulClient(process.env.BITCOINAVERAGE_PUBLIC, process.env.BITCOINAVERAGE_SECRET)
const lnrpc = await require('lnrpc')({ server: 'localhost:10001' })
const adminMacaroon = fs.readFileSync('/home/adam/.lnd.testa/admin.macaroon')
@@ -37,9 +66,8 @@ const l = console.log
const invoices = lnrpc.subscribeInvoices({}, meta)
invoices.on('data', msg => {
- const ds = deepstream('0.0.0.0:6020')
- ds.login()
- ds.event.emit('invoices', msg)
+ let io = socketio()
+ io.emit('invoices', msg)
})
const db = await require('./db.js')(lnrpc)
@@ -121,5 +149,5 @@ const l = console.log
return res.end()
})
- app.listen(3000)
+ server.listen(3000)
})()