Skip to content

Instantly share code, notes, and snippets.

@ralfr
Created January 11, 2018 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfr/3a411a6449ff942b10b45adaaa8528ba to your computer and use it in GitHub Desktop.
Save ralfr/3a411a6449ff942b10b45adaaa8528ba to your computer and use it in GitHub Desktop.
IOTA ZeroMQ Snippet
const zmq = require('zeromq')
const config = require('./config')
var sock = zmq.socket('sub')
sock.connect('tcp://' + config.zmq_url)
sock.subscribe('')
sock.on('message', function(topic) {
console.log(arr)
var tp = topic.toString()
var arr = tp.split(' ')
console.log(JSON.stringify(arr))
if (arr[0] === 'tx') {
let msg = {
hash: arr[1],
'address': arr[2],
'amount': arr[3],
'tag': arr[4],
'timestamp': arr[5],
'currentIndex': arr[6],
'lastIndex': arr[7],
'bundle': arr[8],
'trunk': arr[9],
'branch': arr[10],
'arrivalDate': arr[11]
}
// console.log(arr[0], msg)
} else if (arr[0] === 'sn') {
let msg = {
milestone: arr[1],
tx1: arr[2],
tx2: arr[3],
tx3: arr[4],
tx4: arr[5],
tx5: arr[6]
}
// console.log(msg)
} else {
console.log( arr)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment