Comparing version 0.2.0 to 0.2.1
@@ -644,2 +644,68 @@ var ws = require('ws'); | ||
// Stream | ||
Steem.prototype.streamBlockNumber = function(callback) { | ||
var current = ''; | ||
var w = new ws(this.url); | ||
w.onmessage = function(msg) { | ||
var data = JSON.parse(msg.data); | ||
var blockId = data.result.head_block_number; | ||
if (blockId != current) { | ||
current = blockId; | ||
callback(current); | ||
} | ||
}; | ||
w.onopen = function() { | ||
setInterval(function () { | ||
w.send(JSON.stringify({ | ||
'id': 0, | ||
'method': 'get_dynamic_global_properties', | ||
'params': [] | ||
})); | ||
}, 100); | ||
} | ||
}; | ||
Steem.prototype.streamBlock = function(callback) { | ||
var w = new ws(this.url); | ||
var current = ''; | ||
var last = ''; | ||
this.streamBlockNumber(function(id) { | ||
current = id; | ||
}); | ||
var self = this; | ||
w.onopen = function() { | ||
setInterval(function () { | ||
if (current != last) { | ||
last = current; | ||
self.getBlock(current, function(result) { | ||
callback(result); | ||
}); | ||
} | ||
}, 100); | ||
} | ||
}; | ||
Steem.prototype.streamTransactions = function(callback) { | ||
this.streamBlock(function(result) { | ||
result.transactions.forEach(function (transaction) { | ||
callback(transaction); | ||
}); | ||
}) | ||
}; | ||
Steem.prototype.streamOperations = function(callback) { | ||
this.streamBlock(function(result) { | ||
result.transactions.forEach(function (transaction) { | ||
transaction.operations.forEach(function (operation) { | ||
callback(operation); | ||
}); | ||
}); | ||
}) | ||
}; | ||
module.exports = Steem; |
{ | ||
"name": "steem", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "SteemJS the JavaScript API for Steem blockchain", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -402,2 +402,28 @@ # SteemJS | ||
## Stream | ||
### Stream Block Number | ||
```js | ||
steem.streamBlockNumber(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
### Stream Block | ||
```js | ||
steem.streamBlock(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
### Stream Transactions | ||
```js | ||
steem.streamTransactions(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
### Stream Operations | ||
```js | ||
steem.streamOperations(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
## To-Do | ||
@@ -404,0 +430,0 @@ - Connect all the others API |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
440
0
26826
7
631