From 062b26b0a732127dbfca06890857aaa68e363df8 Mon Sep 17 00:00:00 2001 From: adcpm <fabien@adcpm.com> Date: Sat, 20 Aug 2016 00:25:29 +0700 Subject: [PATCH] - Reputation formatter added - Vest to Steem formatter added - Now var steem has steem.api and steem.formatter subs - Doc updated - test.js updated with mixed samples --- README.md | 15 ++-- browser.js | 4 + dev.js | 7 +- doc/README.md | 156 +++++++++++++++++--------------- examples/index.html | 2 +- index.js | 5 +- lib/{steem.js => api.js} | 189 ++++++++++++++++++++------------------- lib/browser.js | 2 - lib/formatter.js | 23 +++++ lib/steem.min.js | 1 - package.json | 4 +- test.js | 20 +++-- 12 files changed, 243 insertions(+), 185 deletions(-) create mode 100644 browser.js rename lib/{steem.js => api.js} (78%) delete mode 100644 lib/browser.js create mode 100644 lib/formatter.js delete mode 100644 lib/steem.min.js diff --git a/README.md b/README.md index 1f29dd9..c037863 100644 --- a/README.md +++ b/README.md @@ -35,28 +35,33 @@ wss://node.steem.ws By @xerox And @jesta<br/> ## Examples ### Get Accounts ```js -var Steem = require('steem'); -var steem = new Steem(); +var steem = require('steem'); -steem.getAccounts(['ned', 'dan'], function(err, result) { +steem.api.getAccounts(['ned', 'dan'], function(err, result) { console.log(err, result); }); ``` ### Get State ```js -steem.getState('/trends/funny', function(err, result) { +steem.api.getState('/trends/funny', function(err, result) { console.log(err, result); }); ``` ### Get Config ```js -steem.getConfig(function(err, result) { +steem.api.getConfig(function(err, result) { console.log(err, result); }); ``` +### Reputation Formatter +```js +var reputation = steem.formatter.reputation(user.reputation); +console.log(reputation); +``` + ## Contributions Patches are welcome! Contributors are listed in the package.json file. Please run the tests before opening a pull request and make sure that you are passing all of them. If you would like to contribute, but don't know what to work on, check the issues list or on Slack https://steem.slack.com/ channel #steemjs. diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..c75f16e --- /dev/null +++ b/browser.js @@ -0,0 +1,4 @@ +module.exports = { + api: require('./lib/api'), + formatter: require('./lib/formatter'), +}; \ No newline at end of file diff --git a/dev.js b/dev.js index 2dbf94b..61e06e2 100644 --- a/dev.js +++ b/dev.js @@ -1,7 +1,6 @@ -var Steem = require('./lib/steem'), - steem = new Steem(); +var steem = require('./index'); -steem.login('******', '****************', function(err, result) { +steem.api.login('******', '****************', function(err, result) { console.log(result); var trx = { expiration: '2016-08-13T05:44:15', @@ -16,7 +15,7 @@ steem.login('******', '****************', function(err, result) { ref_block_prefix: 3483617648, signatures: ['10f7ce6fc9f5bc99fe789af9e464ff62e6b676622611abd22ed332f20649797b13e0ff85a1be1b72bc26f2ba0d4bf6eStef'] }; - steem.broadcastTransaction(trx, function(err, result) { + steem.api.broadcastTransaction(trx, function(err, result) { console.log(err, result); }); }); \ No newline at end of file diff --git a/doc/README.md b/doc/README.md index 0038abb..c9a2877 100644 --- a/doc/README.md +++ b/doc/README.md @@ -8,25 +8,25 @@ $ npm install steem --save ## Subscriptions ### Set Subscribe Callback ```js -steem.setSubscribeCallback(cb, clearFilter, function(err, result) { +steem.api.setSubscribeCallback(cb, clearFilter, function(err, result) { console.log(err, result); }); ``` ### Set Pending Transaction Callback ```js -steem.setPendingTransactionCallback(cb, function(err, result) { +steem.api.setPendingTransactionCallback(cb, function(err, result) { console.log(err, result); }); ``` ### Set Block Applied Callback ```js -steem.setBlockAppliedCallback(cb, function(err, result) { +steem.api.setBlockAppliedCallback(cb, function(err, result) { console.log(err, result); }); ``` ### Cancel All Subscriptions ```js -steem.cancelAllSubscriptions(function(err, result) { +steem.api.cancelAllSubscriptions(function(err, result) { console.log(err, result); }); ``` @@ -34,61 +34,61 @@ steem.cancelAllSubscriptions(function(err, result) { ## Tags ### Get Trending Tags ```js -steem.getTrendingTags(afterTag, limit, function(err, result) { +steem.api.getTrendingTags(afterTag, limit, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Trending ```js -steem.getDiscussionsByTrending(query, function(err, result) { +steem.api.getDiscussionsByTrending(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Created ```js -steem.getDiscussionsByCreated(query, function(err, result) { +steem.api.getDiscussionsByCreated(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Active ```js -steem.getDiscussionsByActive(query, function(err, result) { +steem.api.getDiscussionsByActive(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Cashout ```js -steem.getDiscussionsByCashout(query, function(err, result) { +steem.api.getDiscussionsByCashout(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Payout ```js -steem.getDiscussionsByPayout(query, function(err, result) { +steem.api.getDiscussionsByPayout(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Votes ```js -steem.getDiscussionsByVotes(query, function(err, result) { +steem.api.getDiscussionsByVotes(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Children ```js -steem.getDiscussionsByChildren(query, function(err, result) { +steem.api.getDiscussionsByChildren(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Hot ```js -steem.getDiscussionsByHot(query, function(err, result) { +steem.api.getDiscussionsByHot(query, function(err, result) { console.log(err, result); }); ``` ### Get Discussions By Feed ```js -steem.getDiscussionsByFeed(query, function(err, result) { +steem.api.getDiscussionsByFeed(query, function(err, result) { console.log(err, result); }); ``` @@ -96,43 +96,43 @@ steem.getDiscussionsByFeed(query, function(err, result) { ## Blocks And Transactions ### Get Block Header ```js -steem.getBlockHeader(blockNum, function(err, result) { +steem.api.getBlockHeader(blockNum, function(err, result) { console.log(err, result); }); ``` ### Get Block ```js -steem.getBlock(blockNum, function(err, result) { +steem.api.getBlock(blockNum, function(err, result) { console.log(err, result); }); ``` ### Get State ```js -steem.getState(path, function(err, result) { +steem.api.getState(path, function(err, result) { console.log(err, result); }); ``` ### Get Trending Categories ```js -steem.getTrendingCategories(after, limit, function(err, result) { +steem.api.getTrendingCategories(after, limit, function(err, result) { console.log(err, result); }); ``` ### Get Best Categories ```js -steem.getBestCategories(after, limit, function(err, result) { +steem.api.getBestCategories(after, limit, function(err, result) { console.log(err, result); }); ``` ### Get Active Categories ```js -steem.getActiveCategories(after, limit, function(err, result) { +steem.api.getActiveCategories(after, limit, function(err, result) { console.log(err, result); }); ``` ### Get Recent Categories ```js -steem.getRecentCategories(after, limit, function(err, result) { +steem.api.getRecentCategories(after, limit, function(err, result) { console.log(err, result); }); ``` @@ -140,49 +140,49 @@ steem.getRecentCategories(after, limit, function(err, result) { ## Globals ### Get Config ```js -steem.getConfig(function(err, result) { +steem.api.getConfig(function(err, result) { console.log(err, result); }); ``` ### Get Dynamic Global Properties ```js -steem.getDynamicGlobalProperties(function(err, result) { +steem.api.getDynamicGlobalProperties(function(err, result) { console.log(err, result); }); ``` ### Get Chain Properties ```js -steem.getChainProperties(after, limit, function(err, result) { +steem.api.getChainProperties(after, limit, function(err, result) { console.log(err, result); }); ``` ### Get Feed History ```js -steem.getFeedHistory(function(err, result) { +steem.api.getFeedHistory(function(err, result) { console.log(err, result); }); ``` ### Get Current Median History Price ```js -steem.getCurrentMedianHistoryPrice(function(err, result) { +steem.api.getCurrentMedianHistoryPrice(function(err, result) { console.log(err, result); }); ``` ### Get Witness Schedule ```js -steem.getWitnessSchedule(function(err, result) { +steem.api.getWitnessSchedule(function(err, result) { console.log(err, result); }); ``` ### Get Hardfork Version ```js -steem.getHardforkVersion(function(err, result) { +steem.api.getHardforkVersion(function(err, result) { console.log(err, result); }); ``` ### Get Next Scheduled Hardfork ```js -steem.getNextScheduledHardfork(function(err, result) { +steem.api.getNextScheduledHardfork(function(err, result) { console.log(err, result); }); ``` @@ -190,7 +190,7 @@ steem.getNextScheduledHardfork(function(err, result) { ## Keys ### Get Key References ```js -steem.getKeyReferences(key, function(err, result) { +steem.api.getKeyReferences(key, function(err, result) { console.log(err, result); }); ``` @@ -198,55 +198,55 @@ steem.getKeyReferences(key, function(err, result) { ## Accounts ### Get Accounts ```js -steem.getAccounts(names, function(err, result) { +steem.api.getAccounts(names, function(err, result) { console.log(err, result); }); ``` ### Get Account References ```js -steem.getAccountReferences(accountId, function(err, result) { +steem.api.getAccountReferences(accountId, function(err, result) { console.log(err, result); }); ``` ### Lookup Account Names ```js -steem.lookupAccountNames(accountNames, function(err, result) { +steem.api.lookupAccountNames(accountNames, function(err, result) { console.log(err, result); }); ``` ### Lookup Accounts ```js -steem.lookupAccounts(lowerBoundName, limit, function(err, result) { +steem.api.lookupAccounts(lowerBoundName, limit, function(err, result) { console.log(err, result); }); ``` ### Get Account Count ```js -steem.getAccountCount(function(err, result) { +steem.api.getAccountCount(function(err, result) { console.log(err, result); }); ``` ### Get Conversion Requests ```js -steem.getConversionRequests(accountName, function(err, result) { +steem.api.getConversionRequests(accountName, function(err, result) { console.log(err, result); }); ``` ### Get Account History ```js -steem.getAccountHistory(account, from, limit, function(err, result) { +steem.api.getAccountHistory(account, from, limit, function(err, result) { console.log(err, result); }); ``` ### Get Owner History ```js -steem.getOwnerHistory(account, function(err, result) { +steem.api.getOwnerHistory(account, function(err, result) { console.log(err, result); }); ``` ### Get Recovery Request ```js -steem.getRecoveryRequest(account, function(err, result) { +steem.api.getRecoveryRequest(account, function(err, result) { console.log(err, result); }); ``` @@ -254,19 +254,19 @@ steem.getRecoveryRequest(account, function(err, result) { ## Market ### Get Order Book ```js -steem.getOrderBook(limit, function(err, result) { +steem.api.getOrderBook(limit, function(err, result) { console.log(err, result); }); ``` ### Get Open Orders ```js -steem.getOpenOrders(owner, function(err, result) { +steem.api.getOpenOrders(owner, function(err, result) { console.log(err, result); }); ``` ### Get Liquidity Queue ```js -steem.getLiquidityQueue(startAccount, limit, function(err, result) { +steem.api.getLiquidityQueue(startAccount, limit, function(err, result) { console.log(err, result); }); ``` @@ -274,37 +274,37 @@ steem.getLiquidityQueue(startAccount, limit, function(err, result) { ## Authority / Validation ### Get Transaction Hex ```js -steem.getTransactionHex(trx, function(err, result) { +steem.api.getTransactionHex(trx, function(err, result) { console.log(err, result); }); ``` ### Get Transaction ```js -steem.getTransaction(trxId, function(err, result) { +steem.api.getTransaction(trxId, function(err, result) { console.log(err, result); }); ``` ### Get Required Signatures ```js -steem.getRequiredSignatures(trx, availableKeys, function(err, result) { +steem.api.getRequiredSignatures(trx, availableKeys, function(err, result) { console.log(err, result); }); ``` ### Get Potential Signatures ```js -steem.getPotentialSignatures(trx, function(err, result) { +steem.api.getPotentialSignatures(trx, function(err, result) { console.log(err, result); }); ``` ### Verify Authority ```js -steem.verifyAuthority(trx, function(err, result) { +steem.api.verifyAuthority(trx, function(err, result) { console.log(err, result); }); ``` ### Verify Account Authority ```js -steem.verifyAccountAuthority(nameOrId, signers, function(err, result) { +steem.api.verifyAccountAuthority(nameOrId, signers, function(err, result) { console.log(err, result); }); ``` @@ -312,13 +312,13 @@ steem.verifyAccountAuthority(nameOrId, signers, function(err, result) { ## Votes ### Get Active Votes ```js -steem.getActiveVotes(author, permlink, function(err, result) { +steem.api.getActiveVotes(author, permlink, function(err, result) { console.log(err, result); }); ``` ### Get Account Votes ```js -steem.getAccountVotes(voter, function(err, result) { +steem.api.getAccountVotes(voter, function(err, result) { console.log(err, result); }); ``` @@ -326,25 +326,25 @@ steem.getAccountVotes(voter, function(err, result) { ## Content ### Get Content ```js -steem.getContent(author, permlink, function(err, result) { +steem.api.getContent(author, permlink, function(err, result) { console.log(err, result); }); ``` ### Get Content Replies ```js -steem.getContentReplies(parent, parentPermlink, function(err, result) { +steem.api.getContentReplies(parent, parentPermlink, function(err, result) { console.log(err, result); }); ``` ### Get Discussion By Author Before Date ```js -steem.getDiscussionsByAuthorBeforeDate(author, startPermlink, beforeDate, limit, function(err, result) { +steem.api.getDiscussionsByAuthorBeforeDate(author, startPermlink, beforeDate, limit, function(err, result) { console.log(err, result); }); ``` ### Get Replies By Last Update ```js -steem.getRepliesByLastUpdate(startAuthor, startPermlink, limit, function(err, result) { +steem.api.getRepliesByLastUpdate(startAuthor, startPermlink, limit, function(err, result) { console.log(err, result); }); ``` @@ -352,50 +352,50 @@ steem.getRepliesByLastUpdate(startAuthor, startPermlink, limit, function(err, re ## Witnesses ### Get Witnesses ```js -steem.getWitnesses(witnessIds, function(err, result) { +steem.api.getWitnesses(witnessIds, function(err, result) { console.log(err, result); }); ``` ### Get Witness By Account ```js -steem.getWitnessByAccount(accountName, function(err, result) { +steem.api.getWitnessByAccount(accountName, function(err, result) { console.log(err, result); }); ``` ### Get Witnesses By Vote ```js -steem.getWitnessesByVote(from, limit, function(err, result) { +steem.api.getWitnessesByVote(from, limit, function(err, result) { console.log(err, result); }); ``` ### Lookup Witness Accounts ```js -steem.lookupWitnessAccounts(lowerBoundName, limit, function(err, result) { +steem.api.lookupWitnessAccounts(lowerBoundName, limit, function(err, result) { console.log(err, result); }); ``` ### Get Witness Count ```js -steem.getWitnessCount(function(err, result) { +steem.api.getWitnessCount(function(err, result) { console.log(err, result); }); ``` ### Get Active Witnesses ```js -steem.getActiveWitnesses(function(err, result) { +steem.api.getActiveWitnesses(function(err, result) { console.log(err, result); }); ``` ### Get Miner Queue ```js -steem.getMinerQueue(function(err, result) { +steem.api.getMinerQueue(function(err, result) { console.log(err, result); }); ``` ## Login ```js -steem.login('ned', '****************', function(err, result) { +steem.api.login('ned', '****************', function(err, result) { console.log(err, result); }); ``` @@ -403,13 +403,13 @@ steem.login('ned', '****************', function(err, result) { ## Follow ### Get Followers ```js -steem.getFollowers(following, startFollower, followType, limit, function(err, result) { +steem.api.getFollowers(following, startFollower, followType, limit, function(err, result) { console.log(err, result); }); ``` ### Get Following ```js -steem.getFollowing(follower, startFollowing, followType, limit, function(err, result) { +steem.api.getFollowing(follower, startFollowing, followType, limit, function(err, result) { console.log(err, result); }); ``` @@ -417,25 +417,25 @@ steem.getFollowing(follower, startFollowing, followType, limit, function(err, re ## Broadcast ### Broadcast Transaction ```js -steem.broadcastTransaction(trx, function(err, result) { +steem.api.broadcastTransaction(trx, function(err, result) { console.log(err, result); }); ``` ### Broadcast Transaction Synchronous ```js -steem.broadcastTransactionSynchronous(trx, function(err, result) { +steem.api.broadcastTransactionSynchronous(trx, function(err, result) { console.log(err, result); }); ``` ### Broadcast Block ```js -steem.broadcastBlock(b, function(err, result) { +steem.api.broadcastBlock(b, function(err, result) { console.log(err, result); }); ``` ### Broadcast Transaction With Callback ```js -steem.broadcastTransactionWithCallback(confirmationCallback, trx, function(err, result) { +steem.api.broadcastTransactionWithCallback(confirmationCallback, trx, function(err, result) { console.log(err, result); }); ``` @@ -443,25 +443,37 @@ steem.broadcastTransactionWithCallback(confirmationCallback, trx, function(err, ## Stream ### Stream Block Number ```js -steem.streamBlockNumber(function(err, result) { +steem.api.streamBlockNumber(function(err, result) { console.log(err, result); }); ``` ### Stream Block ```js -steem.streamBlock(function(err, result) { +steem.api.streamBlock(function(err, result) { console.log(err, result); }); ``` ### Stream Transactions ```js -steem.streamTransactions(function(err, result) { +steem.api.streamTransactions(function(err, result) { console.log(err, result); }); ``` ### Stream Operations ```js -steem.streamOperations(function(err, result) { +steem.api.streamOperations(function(err, result) { console.log(err, result); }); +``` + +## Formatter +### Reputation +```js +var reputation = steem.formatter.reputation(user.reputation); +console.log(reputation); +``` +### Vest To Steem +```js +var power = steem.formatter.vestToSteem(user.vesting_shares, props.total_vesting_shares, props.total_vesting_fund_steem) +console.log(power); ``` \ No newline at end of file diff --git a/examples/index.html b/examples/index.html index 6556c1b..2759f5d 100644 --- a/examples/index.html +++ b/examples/index.html @@ -6,7 +6,7 @@ </head> <body> -<script src="//cdn.steemjs.com/lib/steem.min.js"></script> +<script src="https://cdn.steemjs.com/lib/steem.min.js"></script> <script> steem.getAccounts(['ned', 'dan'], function(err, response){ console.log(err, response); diff --git a/index.js b/index.js index 5f60493..c75f16e 100644 --- a/index.js +++ b/index.js @@ -1 +1,4 @@ -module.exports = require('./lib/steem'); \ No newline at end of file +module.exports = { + api: require('./lib/api'), + formatter: require('./lib/formatter'), +}; \ No newline at end of file diff --git a/lib/steem.js b/lib/api.js similarity index 78% rename from lib/steem.js rename to lib/api.js index 0a627c1..8756451 100644 --- a/lib/steem.js +++ b/lib/api.js @@ -1,24 +1,32 @@ var WebSocket = require('ws'); -var Steem = function(url){ - this.url = url || 'wss://steemit.com/wspa'; - this.apiIds = { +var Steem = { + url: 'wss://steemit.com/wspa', + apiIds: { 'database_api': 0, 'login_api': 1, 'follow_api': 2, 'network_broadcast_api': 4 - }; - this.ws = new WebSocket(this.url); - this.id = 0; - this.reqs = []; - this.isOpen = false; - this.ws.setMaxListeners(0); - this.ws.addEventListener('close', function() { - this.isOpen = false; - }.bind(this)); + }, + id: 0, + reqs: [], + isOpen: false, + isReady: false +}; + +Steem.setWebSocket = function(url) { + this.url = url; }; -Steem.prototype.open = function(callback) { +Steem.init = function(callback) { + if (!this.isReady) { + this.ws = new WebSocket(this.url); + this.ws.setMaxListeners(0); + this.ws.addEventListener('close', function() { + this.isOpen = false; + }.bind(this)); + this.isReady = true; + } if (!this.isOpen) { this.ws.addEventListener('open', function() { this.isOpen = true; @@ -29,14 +37,14 @@ Steem.prototype.open = function(callback) { } }; -Steem.prototype.iterate = function() { +Steem.iterate = function() { this.id++; var id = this.id; this.reqs.push(id); return id; }; -Steem.prototype.getApi = function(api, callback) { +Steem.getApi = function(api, callback) { if (this.apiIds[api] || this.apiIds[api] === 0) { callback('', this.apiIds[api]); } else { @@ -47,10 +55,11 @@ Steem.prototype.getApi = function(api, callback) { } }; -Steem.prototype.send = function(api, data, callback) { +Steem.send = function(api, data, callback) { + data.id = data.id || 0; data.params = data.params || []; - this.open(function(){ + this.init(function(){ var call = {}; call.id = data.id; call.method = 'call'; @@ -75,7 +84,7 @@ Steem.prototype.send = function(api, data, callback) { // Subscriptions /* set_subscribe_callback */ -Steem.prototype.setSubscribeCallback = function(cb, clearFilter, callback) { +Steem.setSubscribeCallback = function(cb, clearFilter, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -87,7 +96,7 @@ Steem.prototype.setSubscribeCallback = function(cb, clearFilter, callback) { }; /* set_pending_transaction_callback */ -Steem.prototype.setPendingTransactionCallback = function(cb, callback) { +Steem.setPendingTransactionCallback = function(cb, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -99,7 +108,7 @@ Steem.prototype.setPendingTransactionCallback = function(cb, callback) { }; /* set_block_applied_callback */ -Steem.prototype.setBlockAppliedCallback = function(cb, callback) { +Steem.setBlockAppliedCallback = function(cb, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -111,7 +120,7 @@ Steem.prototype.setBlockAppliedCallback = function(cb, callback) { }; /* cancel_all_subscriptions */ -Steem.prototype.cancelAllSubscriptions = function(callback) { +Steem.cancelAllSubscriptions = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -125,7 +134,7 @@ Steem.prototype.cancelAllSubscriptions = function(callback) { // tags /* get_trending_tags */ -Steem.prototype.getTrendingTags = function(afterTag, limit, callback) { +Steem.getTrendingTags = function(afterTag, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -137,7 +146,7 @@ Steem.prototype.getTrendingTags = function(afterTag, limit, callback) { }; /* get_discussions_by_trending */ -Steem.prototype.getDiscussionsByTrending = function(query, callback) { +Steem.getDiscussionsByTrending = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -149,7 +158,7 @@ Steem.prototype.getDiscussionsByTrending = function(query, callback) { }; /* get_discussions_by_created */ -Steem.prototype.getDiscussionsByCreated = function(query, callback) { +Steem.getDiscussionsByCreated = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -161,7 +170,7 @@ Steem.prototype.getDiscussionsByCreated = function(query, callback) { }; /* get_discussions_by_active */ -Steem.prototype.getDiscussionsByActive = function(query, callback) { +Steem.getDiscussionsByActive = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -173,7 +182,7 @@ Steem.prototype.getDiscussionsByActive = function(query, callback) { }; /* get_discussions_by_cashout */ -Steem.prototype.getDiscussionsByCashout = function(query, callback) { +Steem.getDiscussionsByCashout = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -185,7 +194,7 @@ Steem.prototype.getDiscussionsByCashout = function(query, callback) { }; /* get_discussions_by_payout */ -Steem.prototype.getDiscussionsByPayout = function(query, callback) { +Steem.getDiscussionsByPayout = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -197,7 +206,7 @@ Steem.prototype.getDiscussionsByPayout = function(query, callback) { }; /* get_discussions_by_votes */ -Steem.prototype.getDiscussionsByVotes = function(query, callback) { +Steem.getDiscussionsByVotes = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -209,7 +218,7 @@ Steem.prototype.getDiscussionsByVotes = function(query, callback) { }; /* get_discussions_by_children */ -Steem.prototype.getDiscussionsByChildren = function(query, callback) { +Steem.getDiscussionsByChildren = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -221,7 +230,7 @@ Steem.prototype.getDiscussionsByChildren = function(query, callback) { }; /* get_discussions_by_hot */ -Steem.prototype.getDiscussionsByHot = function(query, callback) { +Steem.getDiscussionsByHot = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -233,7 +242,7 @@ Steem.prototype.getDiscussionsByHot = function(query, callback) { }; /* get_discussions_by_feed */ -Steem.prototype.getDiscussionsByFeed = function(query, callback) { +Steem.getDiscussionsByFeed = function(query, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -247,7 +256,7 @@ Steem.prototype.getDiscussionsByFeed = function(query, callback) { // Blocks and transactions /* get_block_header */ -Steem.prototype.getBlockHeader = function(blockNum, callback) { +Steem.getBlockHeader = function(blockNum, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -259,7 +268,7 @@ Steem.prototype.getBlockHeader = function(blockNum, callback) { }; /* get_block */ -Steem.prototype.getBlock = function(blockNum, callback) { +Steem.getBlock = function(blockNum, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -271,7 +280,7 @@ Steem.prototype.getBlock = function(blockNum, callback) { }; /* get_state */ -Steem.prototype.getState = function(path, callback) { +Steem.getState = function(path, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -283,7 +292,7 @@ Steem.prototype.getState = function(path, callback) { }; /* get_trending_categories */ -Steem.prototype.getTrendingCategories = function(after, limit, callback) { +Steem.getTrendingCategories = function(after, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -295,7 +304,7 @@ Steem.prototype.getTrendingCategories = function(after, limit, callback) { }; /* get_best_categories */ -Steem.prototype.getBestCategories = function(after, limit, callback) { +Steem.getBestCategories = function(after, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -307,7 +316,7 @@ Steem.prototype.getBestCategories = function(after, limit, callback) { }; /* get_active_categories */ -Steem.prototype.getActiveCategories = function(after, limit, callback) { +Steem.getActiveCategories = function(after, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -319,7 +328,7 @@ Steem.prototype.getActiveCategories = function(after, limit, callback) { }; /* get_recent_categories */ -Steem.prototype.getRecentCategories = function(after, limit, callback) { +Steem.getRecentCategories = function(after, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -334,7 +343,7 @@ Steem.prototype.getRecentCategories = function(after, limit, callback) { // Globals /* get_config */ -Steem.prototype.getConfig = function(callback) { +Steem.getConfig = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -345,7 +354,7 @@ Steem.prototype.getConfig = function(callback) { }; /* get_dynamic_global_properties */ -Steem.prototype.getDynamicGlobalProperties = function(callback) { +Steem.getDynamicGlobalProperties = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -356,7 +365,7 @@ Steem.prototype.getDynamicGlobalProperties = function(callback) { }; /* get_chain_properties */ -Steem.prototype.getChainProperties = function(after, limit, callback) { +Steem.getChainProperties = function(after, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -367,7 +376,7 @@ Steem.prototype.getChainProperties = function(after, limit, callback) { }; /* get_feed_history */ -Steem.prototype.getFeedHistory = function(callback) { +Steem.getFeedHistory = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -378,7 +387,7 @@ Steem.prototype.getFeedHistory = function(callback) { }; /* get_current_median_history_price */ -Steem.prototype.getCurrentMedianHistoryPrice = function(callback) { +Steem.getCurrentMedianHistoryPrice = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -389,7 +398,7 @@ Steem.prototype.getCurrentMedianHistoryPrice = function(callback) { }; /* get_witness_schedule */ -Steem.prototype.getWitnessSchedule = function(callback) { +Steem.getWitnessSchedule = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -401,7 +410,7 @@ Steem.prototype.getWitnessSchedule = function(callback) { }; /* get_hardfork_version */ -Steem.prototype.getHardforkVersion = function(callback) { +Steem.getHardforkVersion = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -412,7 +421,7 @@ Steem.prototype.getHardforkVersion = function(callback) { }; /* get_next_scheduled_hardfork */ -Steem.prototype.getNextScheduledHardfork = function(callback) { +Steem.getNextScheduledHardfork = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -426,7 +435,7 @@ Steem.prototype.getNextScheduledHardfork = function(callback) { // Keys /* get_key_references */ -Steem.prototype.getKeyReferences = function(key, callback) { +Steem.getKeyReferences = function(key, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -441,7 +450,7 @@ Steem.prototype.getKeyReferences = function(key, callback) { // Accounts /* get_accounts */ -Steem.prototype.getAccounts = function(names, callback) { +Steem.getAccounts = function(names, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -453,7 +462,7 @@ Steem.prototype.getAccounts = function(names, callback) { }; /* get_account_references */ -Steem.prototype.getAccountReferences = function(accountId , callback) { +Steem.getAccountReferences = function(accountId , callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -465,7 +474,7 @@ Steem.prototype.getAccountReferences = function(accountId , callback) { }; /* lookup_account_names */ -Steem.prototype.lookupAccountNames = function(accountNames, callback) { +Steem.lookupAccountNames = function(accountNames, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -477,7 +486,7 @@ Steem.prototype.lookupAccountNames = function(accountNames, callback) { }; /* lookup_accounts */ -Steem.prototype.lookupAccounts = function(lowerBoundName, limit, callback) { +Steem.lookupAccounts = function(lowerBoundName, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -489,7 +498,7 @@ Steem.prototype.lookupAccounts = function(lowerBoundName, limit, callback) { }; /* get_account_count */ -Steem.prototype.getAccountCount = function(callback) { +Steem.getAccountCount = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -500,7 +509,7 @@ Steem.prototype.getAccountCount = function(callback) { }; /* get_conversion_requests */ -Steem.prototype.getConversionRequests = function(accountName, callback) { +Steem.getConversionRequests = function(accountName, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -512,7 +521,7 @@ Steem.prototype.getConversionRequests = function(accountName, callback) { }; /* get_account_history */ -Steem.prototype.getAccountHistory = function(account, from, limit, callback) { +Steem.getAccountHistory = function(account, from, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -524,7 +533,7 @@ Steem.prototype.getAccountHistory = function(account, from, limit, callback) { }; /* get_owner_history */ -Steem.prototype.getOwnerHistory = function(account, callback) { +Steem.getOwnerHistory = function(account, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -536,7 +545,7 @@ Steem.prototype.getOwnerHistory = function(account, callback) { }; /* get_recovery_request */ -Steem.prototype.getRecoveryRequest = function(account, callback) { +Steem.getRecoveryRequest = function(account, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -551,7 +560,7 @@ Steem.prototype.getRecoveryRequest = function(account, callback) { // Market /* get_order_book */ -Steem.prototype.getOrderBook = function(limit, callback) { +Steem.getOrderBook = function(limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -563,7 +572,7 @@ Steem.prototype.getOrderBook = function(limit, callback) { }; /* get_open_orders */ -Steem.prototype.getOpenOrders = function(owner, callback) { +Steem.getOpenOrders = function(owner, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -575,7 +584,7 @@ Steem.prototype.getOpenOrders = function(owner, callback) { }; /* get_liquidity_queue */ -Steem.prototype.getLiquidityQueue = function(startAccount, limit, callback) { +Steem.getLiquidityQueue = function(startAccount, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -590,7 +599,7 @@ Steem.prototype.getLiquidityQueue = function(startAccount, limit, callback) { // Authority / validation /* get_transaction_hex */ -Steem.prototype.getTransactionHex = function(trx, callback) { +Steem.getTransactionHex = function(trx, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -602,7 +611,7 @@ Steem.prototype.getTransactionHex = function(trx, callback) { }; /* get_transaction */ -Steem.prototype.getTransaction = function(trxId, callback) { +Steem.getTransaction = function(trxId, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -614,7 +623,7 @@ Steem.prototype.getTransaction = function(trxId, callback) { }; /* get_required_signatures */ -Steem.prototype.getRequiredSignatures = function(trx, availableKeys, callback) { +Steem.getRequiredSignatures = function(trx, availableKeys, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -626,7 +635,7 @@ Steem.prototype.getRequiredSignatures = function(trx, availableKeys, callback) { }; /* get_potential_signatures */ -Steem.prototype.getPotentialSignatures = function(trx, callback) { +Steem.getPotentialSignatures = function(trx, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -638,7 +647,7 @@ Steem.prototype.getPotentialSignatures = function(trx, callback) { }; /* verify_authority */ -Steem.prototype.verifyAuthority = function(trx, callback) { +Steem.verifyAuthority = function(trx, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -650,7 +659,7 @@ Steem.prototype.verifyAuthority = function(trx, callback) { }; /* verify_account_authority */ -Steem.prototype.verifyAccountAuthority = function(nameOrId, signers, callback) { +Steem.verifyAccountAuthority = function(nameOrId, signers, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -665,7 +674,7 @@ Steem.prototype.verifyAccountAuthority = function(nameOrId, signers, callback) { // votes /* get_active_votes */ -Steem.prototype.getActiveVotes = function(author, permlink, callback) { +Steem.getActiveVotes = function(author, permlink, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -677,7 +686,7 @@ Steem.prototype.getActiveVotes = function(author, permlink, callback) { }; /* get_account_votes */ -Steem.prototype.getAccountVotes = function(voter, callback) { +Steem.getAccountVotes = function(voter, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -692,7 +701,7 @@ Steem.prototype.getAccountVotes = function(voter, callback) { // content /* get_content */ -Steem.prototype.getContent = function(author, permlink, callback) { +Steem.getContent = function(author, permlink, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -704,7 +713,7 @@ Steem.prototype.getContent = function(author, permlink, callback) { }; /* get_content_replies */ -Steem.prototype.getContentReplies = function(parent, parentPermlink, callback) { +Steem.getContentReplies = function(parent, parentPermlink, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -716,7 +725,7 @@ Steem.prototype.getContentReplies = function(parent, parentPermlink, callback) { }; /* get_discussions_by_author_before_date */ -Steem.prototype.getDiscussionsByAuthorBeforeDate = function(author, startPermlink, beforeDate, limit, callback) { +Steem.getDiscussionsByAuthorBeforeDate = function(author, startPermlink, beforeDate, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -728,7 +737,7 @@ Steem.prototype.getDiscussionsByAuthorBeforeDate = function(author, startPermlin }; /* get_replies_by_last_update */ -Steem.prototype.getRepliesByLastUpdate = function(startAuthor, startPermlink, limit, callback) { +Steem.getRepliesByLastUpdate = function(startAuthor, startPermlink, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -743,7 +752,7 @@ Steem.prototype.getRepliesByLastUpdate = function(startAuthor, startPermlink, li // Witnesses /* get_witnesses */ -Steem.prototype.getWitnesses = function(witnessIds, callback) { +Steem.getWitnesses = function(witnessIds, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -755,7 +764,7 @@ Steem.prototype.getWitnesses = function(witnessIds, callback) { }; /* get_witness_by_account */ -Steem.prototype.getWitnessByAccount = function(accountName, callback) { +Steem.getWitnessByAccount = function(accountName, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -767,7 +776,7 @@ Steem.prototype.getWitnessByAccount = function(accountName, callback) { }; /* get_witnesses_by_vote */ -Steem.prototype.getWitnessesByVote = function(from, limit, callback) { +Steem.getWitnessesByVote = function(from, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -779,7 +788,7 @@ Steem.prototype.getWitnessesByVote = function(from, limit, callback) { }; /* lookup_witness_accounts */ -Steem.prototype.lookupWitnessAccounts = function(lowerBoundName, limit, callback) { +Steem.lookupWitnessAccounts = function(lowerBoundName, limit, callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -791,7 +800,7 @@ Steem.prototype.lookupWitnessAccounts = function(lowerBoundName, limit, callback }; /* get_witness_count */ -Steem.prototype.getWitnessCount = function(callback) { +Steem.getWitnessCount = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -802,7 +811,7 @@ Steem.prototype.getWitnessCount = function(callback) { }; /* get_active_witnesses */ -Steem.prototype.getActiveWitnesses = function(callback) { +Steem.getActiveWitnesses = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -813,7 +822,7 @@ Steem.prototype.getActiveWitnesses = function(callback) { }; /* get_miner_queue */ -Steem.prototype.getMinerQueue = function(callback) { +Steem.getMinerQueue = function(callback) { var iterator = this.iterate(); this.send('database_api', { 'id': iterator, @@ -827,7 +836,7 @@ Steem.prototype.getMinerQueue = function(callback) { // [login_api] /* login */ -Steem.prototype.login = function(username, password, callback) { +Steem.login = function(username, password, callback) { var iterator = this.iterate(); this.send('login_api', { 'id': iterator, @@ -839,7 +848,7 @@ Steem.prototype.login = function(username, password, callback) { }; /* get_api_by_name */ -Steem.prototype.getApiByName = function(apiName, callback) { +Steem.getApiByName = function(apiName, callback) { var iterator = this.iterate(); this.send('login_api', { 'id': iterator, @@ -854,7 +863,7 @@ Steem.prototype.getApiByName = function(apiName, callback) { // [follow_api] /* get_followers */ -Steem.prototype.getFollowers = function(following, startFollower, followType, limit, callback) { +Steem.getFollowers = function(following, startFollower, followType, limit, callback) { var iterator = this.iterate(); this.send('follow_api', { 'id': iterator, @@ -866,7 +875,7 @@ Steem.prototype.getFollowers = function(following, startFollower, followType, li }; /* get_following */ -Steem.prototype.getFollowing = function(follower, startFollowing, followType, limit, callback) { +Steem.getFollowing = function(follower, startFollowing, followType, limit, callback) { var iterator = this.iterate(); this.send('follow_api', { 'id': iterator, @@ -881,7 +890,7 @@ Steem.prototype.getFollowing = function(follower, startFollowing, followType, li // [network_broadcast_api] /* broadcast_transaction */ -Steem.prototype.broadcastTransaction = function(trx, callback) { +Steem.broadcastTransaction = function(trx, callback) { var iterator = this.iterate(); this.send('network_broadcast_api', { 'id': iterator, @@ -893,7 +902,7 @@ Steem.prototype.broadcastTransaction = function(trx, callback) { }; /* broadcast_transaction_synchronous */ -Steem.prototype.broadcastTransactionSynchronous = function(trx , callback) { +Steem.broadcastTransactionSynchronous = function(trx , callback) { var iterator = this.iterate(); this.send('network_broadcast_api', { 'id': iterator, @@ -905,7 +914,7 @@ Steem.prototype.broadcastTransactionSynchronous = function(trx , callback) { }; /* broadcast_block */ -Steem.prototype.broadcastBlock = function(b, callback) { +Steem.broadcastBlock = function(b, callback) { var iterator = this.iterate(); this.send('network_broadcast_api', { 'id': iterator, @@ -917,7 +926,7 @@ Steem.prototype.broadcastBlock = function(b, callback) { }; /* broadcast_transaction_with_callback */ -Steem.prototype.broadcastTransactionWithCallback = function(confirmationCallback, trx, callback) { +Steem.broadcastTransactionWithCallback = function(confirmationCallback, trx, callback) { var iterator = this.iterate(); this.send('network_broadcast_api', { 'id': iterator, @@ -931,7 +940,7 @@ Steem.prototype.broadcastTransactionWithCallback = function(confirmationCallback // [Stream] -Steem.prototype.streamBlockNumber = function(callback) { +Steem.streamBlockNumber = function(callback) { var current = ''; var self = this; setInterval(function() { @@ -945,7 +954,7 @@ Steem.prototype.streamBlockNumber = function(callback) { }, 200); }; -Steem.prototype.streamBlock = function(callback) { +Steem.streamBlock = function(callback) { var current = ''; var last = ''; var self = this; @@ -960,7 +969,7 @@ Steem.prototype.streamBlock = function(callback) { }); }; -Steem.prototype.streamTransactions = function(callback) { +Steem.streamTransactions = function(callback) { this.streamBlock(function(err, result) { if (!!result) { result.transactions.forEach(function(transaction) { @@ -970,7 +979,7 @@ Steem.prototype.streamTransactions = function(callback) { }) }; -Steem.prototype.streamOperations = function(callback) { +Steem.streamOperations = function(callback) { this.streamBlock(function(err, result) { if (!!result) { result.transactions.forEach(function(transaction) { diff --git a/lib/browser.js b/lib/browser.js deleted file mode 100644 index 0cd8850..0000000 --- a/lib/browser.js +++ /dev/null @@ -1,2 +0,0 @@ -var Steem = require('./steem.js'); -steem = new Steem(); \ No newline at end of file diff --git a/lib/formatter.js b/lib/formatter.js new file mode 100644 index 0000000..ac267ea --- /dev/null +++ b/lib/formatter.js @@ -0,0 +1,23 @@ +module.exports = { + reputation: function (reputation) { + if (reputation == null) return reputation; + reputation = parseInt(reputation); + let rep = String(reputation); + const neg = rep.charAt(0) === '-'; + rep = neg ? rep.substring(1) : rep; + var str = rep; + const leadingDigits = parseInt(str.substring(0, 4)); + const log = Math.log(leadingDigits) / Math.log(10); + const n = str.length - 1; + var out = n + (log - parseInt(log)); + if (isNaN(out)) out = 0; + out = Math.max(out - 9, 0); + out = (neg ? -1 : 1) * out; + out = (out * 9) + 25; + out = parseInt(out); + return out; + }, + vestToSteem: function(vestingShares, totalVestingShares, totalVestingFundSteem) { + return parseFloat(totalVestingFundSteem) * (parseFloat(vestingShares) / parseFloat(totalVestingShares)); + } +}; \ No newline at end of file diff --git a/lib/steem.min.js b/lib/steem.min.js deleted file mode 100644 index 53e0906..0000000 --- a/lib/steem.min.js +++ /dev/null @@ -1 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){var Steem=require("./steem.js");steem=new Steem},{"./steem.js":2}],2:[function(require,module,exports){var Steem=function(url){this.url=url||"wss://steemit.com/wspa";this.apiIds={database_api:0,login_api:1,follow_api:2,network_broadcast_api:4};this.ws=new WebSocket(this.url);this.id=0;this.reqs=[];this.isOpen=false;this.ws.addEventListener("close",function(){this.isOpen=false}.bind(this))};Steem.prototype.open=function(callback){if(!this.isOpen){this.ws.addEventListener("open",function(){this.isOpen=true;callback()}.bind(this))}else{callback()}};Steem.prototype.iterate=function(){this.id++;var id=this.id;this.reqs.push(id);return id};Steem.prototype.getApi=function(api,callback){if(this.apiIds[api]||this.apiIds[api]===0){callback("",this.apiIds[api])}else{this.getApiByName(api,function(err,result){this.apiIds[api]=result;callback("",result)}.bind(this))}};Steem.prototype.send=function(api,data,callback){data.id=data.id||0;data.params=data.params||[];this.open(function(){var call={};call.id=data.id;call.method="call";call.params=[this.apiIds[api],data.method,data.params];this.ws.send(JSON.stringify(call))}.bind(this));this.ws.addEventListener("message",function(msg){var data=JSON.parse(msg.data);var err=data.error&&data.error.data&&data.error.data.stack?data.error.data.stack:"";callback(err,data)}.bind(this));this.ws.addEventListener("error",function(error){callback(error,null)})};Steem.prototype.setSubscribeCallback=function(cb,clearFilter,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"set_subscribe_callback",params:[cb,clearFilter]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.setPendingTransactionCallback=function(cb,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"set_pending_transaction_callback",params:[cb]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.setBlockAppliedCallback=function(cb,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"set_block_applied_callback",params:[cb]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.cancelAllSubscriptions=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"cancel_all_subscriptions"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getTrendingTags=function(afterTag,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_trending_tags",params:[afterTag,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByTrending=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_trending",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByCreated=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_created",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByActive=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_active",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByCashout=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_cashout",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByPayout=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_payout",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByVotes=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_votes",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByChildren=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_children",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByHot=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_hot",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByFeed=function(query,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_feed",params:[query]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getBlockHeader=function(blockNum,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_block_header",params:[blockNum]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getBlock=function(blockNum,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_block",params:[blockNum]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getState=function(path,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_state",params:[path]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getTrendingCategories=function(after,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_trending_categories",params:[after,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getBestCategories=function(after,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_best_categories",params:[after,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getActiveCategories=function(after,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_active_categories",params:[after,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getRecentCategories=function(after,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_recent_categories",params:[after,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getConfig=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_config"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDynamicGlobalProperties=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_dynamic_global_properties"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getChainProperties=function(after,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_chain_properties"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getFeedHistory=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_feed_history"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getCurrentMedianHistoryPrice=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_current_median_history_price"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getWitnessSchedule=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_recent_categories",params:[after,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getHardforkVersion=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_hardfork_version"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getNextScheduledHardfork=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_next_scheduled_hardfork"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getKeyReferences=function(key,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_key_references",params:[key]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getAccounts=function(names,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_accounts",params:[names]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getAccountReferences=function(accountId,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_account_references",params:[accountId]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.lookupAccountNames=function(accountNames,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"lookup_account_names",params:[accountNames]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.lookupAccounts=function(lowerBoundName,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"lookup_accounts",params:[lowerBoundName,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getAccountCount=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_account_count"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getConversionRequests=function(accountName,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_conversion_requests",params:[accountName]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getAccountHistory=function(account,from,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_account_history",params:[account,from,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getOwnerHistory=function(account,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_owner_history",params:[account]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getRecoveryRequest=function(account,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_recovery_request",params:[account]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getOrderBook=function(limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"getOrderBook",params:[limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getOpenOrders=function(owner,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_open_orders",params:[owner]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getLiquidityQueue=function(startAccount,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_liquidity_queue",params:[startAccount,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getTransactionHex=function(trx,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_transaction_hex",params:[trx]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getTransaction=function(trxId,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_transaction",params:[trxId]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getRequiredSignatures=function(trx,availableKeys,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_required_signatures",params:[trx,availableKeys]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getPotentialSignatures=function(trx,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_potential_signatures",params:[trx]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.verifyAuthority=function(trx,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"verify_authority",params:[trx]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.verifyAccountAuthority=function(nameOrId,signers,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"verify_account_authority",params:[nameOrId,signers]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getActiveVotes=function(author,permlink,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_active_votes",params:[author,permlink]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getAccountVotes=function(voter,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_account_votes",params:[voter]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getContent=function(author,permlink,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_content",params:[author,permlink]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getContentReplies=function(parent,parentPermlink,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_content_replies",params:[parent,parentPermlink]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getDiscussionsByAuthorBeforeDate=function(author,startPermlink,beforeDate,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_discussions_by_author_before_date",params:[author,startPermlink,beforeDate,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getRepliesByLastUpdate=function(startAuthor,startPermlink,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_replies_by_last_update",params:[startAuthor,startPermlink,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getWitnesses=function(witnessIds,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_witnesses",params:[witnessIds]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getWitnessByAccount=function(accountName,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_witness_by_account",params:[accountName]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getWitnessesByVote=function(from,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_witnesses_by_vote",params:[from,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.lookupWitnessAccounts=function(lowerBoundName,limit,callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"lookup_witness_accounts",params:[lowerBoundName,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getWitnessCount=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_witness_count"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getActiveWitnesses=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_active_witnesses"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getMinerQueue=function(callback){var iterator=this.iterate();this.send("database_api",{id:iterator,method:"get_miner_queue"},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.login=function(username,password,callback){var iterator=this.iterate();this.send("login_api",{id:iterator,method:"login",params:[username,password]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getApiByName=function(apiName,callback){var iterator=this.iterate();this.send("login_api",{id:iterator,method:"get_api_by_name",params:[apiName]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getFollowers=function(following,startFollower,followType,limit,callback){var iterator=this.iterate();this.send("follow_api",{id:iterator,method:"get_followers",params:[following,startFollower,followType,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.getFollowing=function(follower,startFollowing,followType,limit,callback){var iterator=this.iterate();this.send("follow_api",{id:iterator,method:"get_following",params:[follower,startFollowing,followType,limit]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.broadcastTransaction=function(trx,callback){var iterator=this.iterate();this.send("network_broadcast_api",{id:iterator,method:"broadcast_transaction",params:[trx]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.broadcastTransactionSynchronous=function(trx,callback){var iterator=this.iterate();this.send("network_broadcast_api",{id:iterator,method:"broadcast_transaction_synchronous",params:[trx]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.broadcastBlock=function(b,callback){var iterator=this.iterate();this.send("network_broadcast_api",{id:iterator,method:"broadcast_block",params:[b]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.broadcastTransactionWithCallback=function(confirmationCallback,trx,callback){var iterator=this.iterate();this.send("network_broadcast_api",{id:iterator,method:"broadcast_transaction_with_callback",params:[confirmationCallback,trx]},function(err,data){if(iterator==data.id)callback(err,data.result)})};Steem.prototype.streamBlockNumber=function(callback){var current="";var self=this;setInterval(function(){self.getDynamicGlobalProperties(function(err,result){var blockId=result.head_block_number;if(blockId!=current){current=blockId;callback(null,current)}})},200)};Steem.prototype.streamBlock=function(callback){var current="";var last="";var self=this;this.streamBlockNumber(function(err,id){current=id;if(current!=last){last=current;self.getBlock(current,function(err,result){callback(null,result)})}})};Steem.prototype.streamTransactions=function(callback){this.streamBlock(function(err,result){if(!!result){result.transactions.forEach(function(transaction){callback(null,transaction)})}})};Steem.prototype.streamOperations=function(callback){this.streamBlock(function(err,result){if(!!result){result.transactions.forEach(function(transaction){transaction.operations.forEach(function(operation){callback(null,operation)})})}})};module.exports=Steem},{}]},{},[1]); diff --git a/package.json b/package.json index 1c7f7a9..45fc3de 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "steem", - "version": "0.2.21", + "version": "0.3.0", "description": "Steem.js the JavaScript API for Steem blockchain", "main": "index.js", "scripts": { "test": "node test.js", - "build": "browserify lib/browser.js -o | uglifyjs > lib/steem.min.js && browserify lib/browser.js -o | uglifyjs > examples/steem.min.js" + "build": "browserify browser.js -o | uglifyjs > lib/steem.min.js && browserify browser.js -o | uglifyjs > examples/steem.min.js" }, "repository": { "type": "git", diff --git a/test.js b/test.js index 8407388..d794cc4 100644 --- a/test.js +++ b/test.js @@ -1,22 +1,28 @@ -var steem = require('./lib/steem'), - steem = new Steem(); +var steem = require('./index'); -steem.getAccountCount(function(err, result) { +steem.api.getAccountCount(function(err, result) { console.log(err, result); }); -steem.getAccounts(['dan'], function(err, result) { +steem.api.getAccounts(['dan'], function(err, result) { + console.log(err, result); + + var reputation = steem.formatter.reputation(result[0].reputation); + console.log(reputation); +}); + +steem.api.getState('trending/steemit', function(err, result) { console.log(err, result); }); -steem.getState('trending/steemit', function(err, result) { +steem.api.getFollowing('ned', 0, 'blog', 10, function(err, result) { console.log(err, result); }); -steem.getFollowing('ned', 0, 'blog', 10, function(err, result) { +steem.api.getFollowers('dan', 0, 'blog', 10, function(err, result) { console.log(err, result); }); -steem.getFollowers('dan', 0, 'blog', 10, function(err, result) { +steem.api.streamOperations(function(err, result) { console.log(err, result); }); \ No newline at end of file -- GitLab