Comparing version 0.0.2 to 0.1.0
115
lib/steem.js
@@ -1,3 +0,116 @@ | ||
var Steem = 'test'; | ||
var ws = require('ws'); | ||
var Steem = function(url){ | ||
this.url = url || 'wss://this.piston.rocks'; | ||
}; | ||
Steem.prototype.send = function(data, callback) { | ||
var w = new ws(this.url); | ||
w.onmessage = function(msg) { | ||
var data = JSON.parse(msg.data); | ||
var err = data.error || ''; | ||
callback(data.result, err); | ||
}; | ||
w.onopen = function() { | ||
w.send(JSON.stringify(data)); | ||
} | ||
}; | ||
Steem.prototype.getAccounts = function(usernames, callback) { | ||
this.send({ | ||
'id': 1, | ||
'method': 'get_accounts', | ||
'params': [usernames] | ||
}, function(result, err) { | ||
callback(result, err); | ||
}); | ||
}; | ||
Steem.prototype.getAccount = function(username, callback) { | ||
this.send({ | ||
'id': 1, | ||
'method': 'get_accounts', | ||
'params': [[username]] | ||
}, function(result, err) { | ||
callback(result[0], err); | ||
}); | ||
}; | ||
Steem.prototype.getBlock = function(id, callback) { | ||
this.send({ | ||
'id': 1, | ||
'method': 'get_block', | ||
'params': [id] | ||
}, function(result, err) { | ||
callback(result, err); | ||
}); | ||
}; | ||
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': 1, | ||
'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.0.2", | ||
"description": "Steem Blockchain API", | ||
"version": "0.1.0", | ||
"description": "SteemJS the JavaScript API for Steem blockchain", | ||
"main": "index.js", | ||
@@ -26,4 +26,4 @@ "scripts": { | ||
"dependencies": { | ||
"steem-rpc": "^0.5.2" | ||
"ws": "^1.1.1" | ||
} | ||
} |
@@ -1,2 +0,88 @@ | ||
# Steem | ||
/!\ This package is under development and not working yet. | ||
# SteemJS | ||
## Install | ||
``` | ||
$ npm install steem --save | ||
``` | ||
## Usage | ||
```js | ||
var steem = require('./lib/steem'); | ||
var Steem = new steem(); | ||
Steem.getAccount('steemit', function(result, err) { | ||
console.log(result, err); | ||
}); | ||
``` | ||
## Send | ||
```js | ||
var data = { | ||
'id': 1, | ||
'method': 'get_accounts', | ||
'params': [['steemit']] | ||
}; | ||
Steem.send(data, function(result, err) { | ||
console.log(result, err); | ||
}); | ||
``` | ||
## Get Accounts | ||
```js | ||
Steem.getAccounts(['ned', 'dan'], function(result, err) { | ||
console.log(result, err); | ||
}); | ||
``` | ||
## Get Account | ||
```js | ||
Steem.getAccount('steemit', function(result, err) { | ||
console.log(result, err); | ||
}); | ||
``` | ||
## Get Block | ||
```js | ||
Steem.getBlock(3000000, function(result, err) { | ||
console.log(result, err); | ||
}); | ||
``` | ||
## Streaming Block Number | ||
```js | ||
Steem.streamBlockNumber(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
## Streaming Block | ||
```js | ||
Steem.streamBlock(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
## Streaming Transactions | ||
```js | ||
Steem.streamTransactions(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
## Streaming Operations | ||
```js | ||
Steem.streamOperations(function(result) { | ||
console.log(result); | ||
}); | ||
``` | ||
## License | ||
MIT | ||
Sorry, the diff of this file is not supported yet
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
122
89
0
5267
7
+ Addedws@^1.1.1
+ Addedoptions@0.0.6(transitive)
+ Addedultron@1.0.2(transitive)
+ Addedws@1.1.5(transitive)
- Removedsteem-rpc@^0.5.2
- Removedbufferutil@4.0.9(transitive)
- Removedd@1.0.2(transitive)
- Removeddebug@2.6.9(transitive)
- Removedes5-ext@0.10.64(transitive)
- Removedes6-iterator@2.0.3(transitive)
- Removedes6-symbol@3.1.4(transitive)
- Removedesniff@2.0.1(transitive)
- Removedevent-emitter@0.3.5(transitive)
- Removedext@1.7.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedms@2.0.0(transitive)
- Removednext-tick@1.1.0(transitive)
- Removednode-gyp-build@4.8.4(transitive)
- Removedsteem-rpc@0.5.7(transitive)
- Removedtype@2.7.3(transitive)
- Removedtypedarray-to-buffer@3.1.5(transitive)
- Removedutf-8-validate@5.0.10(transitive)
- Removedwebsocket@1.0.35(transitive)
- Removedyaeti@0.0.6(transitive)