diff --git a/.gitignore b/.gitignore index 2621e29e777421a5aa5e8311a8c8f4455eb16928..19ce7c3b2314ce50f9bf00a125b2638899acdb13 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ scr *.css.map *.css dev.js +test.js # Logs logs diff --git a/.npmignore b/.npmignore index c0fde0d6d4610fd2976c7bf02054a9320729eb0e..8b0cbe1335958414dc01989beb327a0229c465a2 100644 --- a/.npmignore +++ b/.npmignore @@ -2,4 +2,5 @@ .idea src npm-debug.log -dev.js \ No newline at end of file +dev.js +test.js \ No newline at end of file diff --git a/README.md b/README.md index e5789f032d458d24805ccaf7a54ca7619f45da6b..5fa4d78626c3ded4f5f35c4aff76fe442c30c849 100644 --- a/README.md +++ b/README.md @@ -33,25 +33,25 @@ wss://node.steem.ws<br/> wss://this.piston.rocks<br/> ## Examples -### Get Accounts +### Broadcast Vote ```js var steem = require('steem'); -steem.api.getAccounts(['ned', 'dan'], function(err, result) { +steem.broadcast.vote(username, password, author, permlink, weight, function(err, result) { console.log(err, result); }); ``` -### Get State -```js -steem.api.getState('/trends/funny', function(err, result) { +### Get Accounts +```js +steem.api.getAccounts(['ned', 'dan'], function(err, result) { console.log(err, result); }); ``` -### Get Config +### Get State ```js -steem.api.getConfig(function(err, result) { +steem.api.getState('/trends/funny', function(err, result) { console.log(err, result); }); ``` diff --git a/browser.js b/browser.js deleted file mode 100644 index c75f16ed4bbad035d2ca6b2cea5d18d6b60514fd..0000000000000000000000000000000000000000 --- a/browser.js +++ /dev/null @@ -1,4 +0,0 @@ -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 ac18b163b64cf614702355179ea1459e346c10fd..43ea805c52ea6e90a1c1a524f47129db9384e074 100644 --- a/dev.js +++ b/dev.js @@ -1,21 +1,4 @@ var steem = require('./index'); -steem.api.login('******', '****************', function(err, result) { - console.log(result); - var trx = { - expiration: '2016-08-20T02:59:51', - extensions: [], - operations: [['vote', { - voter: 'siol', - author: 'rogerkver', - permlink: 'roger-ver-the-world-s-first-bitcoin-investor-is-now-on-steemit', - weight: 10000 - }]], - ref_block_num: 40607, - ref_block_prefix: 2394871259, - signatures: ['206239640514a1aac6ef29b0fdf7bf1f1457526a77bb4cb35bc82d7f614d271bb54783850b6da824db5cf787d7a7b9b8a1da5fd3d2c2ebf53437906fc93f45d238'] - }; - steem.api.broadcastTransaction(trx, function(err, result) { - console.log(err, result); - }); -}); \ No newline at end of file +var username = process.env.STEEM_USERNAME; +var password = process.env.STEEM_PASSWORD; diff --git a/doc/README.md b/doc/README.md index c9a2877e25bfbac213798c927f55a23874382d9c..763daf9c2d29881c64fffca533391acf66ca883f 100644 --- a/doc/README.md +++ b/doc/README.md @@ -476,4 +476,12 @@ console.log(reputation); ```js var power = steem.formatter.vestToSteem(user.vesting_shares, props.total_vesting_shares, props.total_vesting_fund_steem) console.log(power); +``` + +## Broadcast +### Vote +```js +steem.broadcast.vote(username, password, author, permlink, weight, function(err, result) { + console.log(err, result); +}); ``` \ No newline at end of file diff --git a/examples/index.html b/examples/browser.html similarity index 100% rename from examples/index.html rename to examples/browser.html diff --git a/examples/server.js b/examples/server.js new file mode 100644 index 0000000000000000000000000000000000000000..a1467a6033e8d14bddd936bf94305c47065e09d3 --- /dev/null +++ b/examples/server.js @@ -0,0 +1,29 @@ +var steem = require('./../index'); + +steem.api.getAccountCount(function(err, result) { + console.log(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.api.getFollowing('ned', 0, 'blog', 10, function(err, result) { + console.log(err, result); +}); + +steem.api.getFollowers('dan', 0, 'blog', 10, function(err, result) { + console.log(err, result); +}); + +steem.api.streamOperations(function(err, result) { + if (!err && result[1].author == 'fabien') { + console.log(result); + } +}); \ No newline at end of file diff --git a/index.js b/index.js index c75f16ed4bbad035d2ca6b2cea5d18d6b60514fd..efe8c4647ad5cfd4c24e36d8548f5fc9287d4387 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,6 @@ module.exports = { api: require('./lib/api'), formatter: require('./lib/formatter'), + auth: require('steemauth'), + broadcast: require('./lib/broadcast') }; \ No newline at end of file diff --git a/lib/broadcast.js b/lib/broadcast.js new file mode 100644 index 0000000000000000000000000000000000000000..4f086bcbbdcc43a6fd1d4cbd84c02f26be777f9e --- /dev/null +++ b/lib/broadcast.js @@ -0,0 +1,34 @@ +var moment = require('moment'), + steemAuth = require('steemauth'), + steemApi = require('./api'); + +module.exports = { + send: function(username, password, tx, privKeys, callback) { + steemApi.login(username, password, function() { + steemApi.getDynamicGlobalProperties(function(err, result) { + tx.expiration = moment.utc(result.timestamp).add(15, 'second').format().replace('Z', ''); + tx.ref_block_num = result.head_block_number & 0xFFFF; + tx.ref_block_prefix = new Buffer(result.head_block_id, 'hex').readUInt32LE(4); + var signedTransaction = steemAuth.signTransaction(tx, privKeys); + steemApi.broadcastTransactionWithCallback(function(){}, signedTransaction, function(err, result) { + callback(err, result); + }); + }); + }); + }, + vote: function(username, password, author, permlink, weight, callback) { + var tx = { + extensions: [], + operations: [['vote', { + voter: username, + author: author, + permlink: permlink, + weight: weight + }]] + }; + var privKeys = steemAuth.getPrivateKeys(username, password, ['posting']); + this.send(username, password, tx, privKeys, function(err, result) { + callback(err, result); + }) + } +}; \ No newline at end of file diff --git a/lib/browser.js b/lib/browser.js new file mode 100644 index 0000000000000000000000000000000000000000..8ecce55e0474bd3a38bfd6183c9e11d1f3cb0cff --- /dev/null +++ b/lib/browser.js @@ -0,0 +1,4 @@ +module.exports = { + api: require('./api'), + formatter: require('./formatter'), +}; \ No newline at end of file diff --git a/package.json b/package.json index f11528b2019d7147883296a56d2bf04650f223c9..66af987c2cec68fcd51d1c6860e0fd87b1b8484c 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "steem", - "version": "0.3.7", + "version": "0.3.8", "description": "Steem.js the JavaScript API for Steem blockchain", "main": "index.js", "scripts": { "test": "node test.js", - "build": "browserify browser.js -o | uglifyjs > lib/steem.min.js && browserify browser.js -o | uglifyjs > examples/steem.min.js" + "build": "browserify lib/browser.js -o | uglifyjs > lib/steem.min.js && browserify lib/browser.js -o | uglifyjs > examples/steem.min.js" }, "repository": { "type": "git", @@ -17,13 +17,15 @@ "blockchain", "steemjs" ], - "author": "AdCpm <fabien@adcpm.com> (https://github.com/adcpm)", + "author": "AdCpm <fabien@bonustrack.co> (https://github.com/adcpm)", "license": "MIT", "bugs": { "url": "https://github.com/adcpm/steem/issues" }, "homepage": "https://github.com/adcpm/steem#readme", "dependencies": { + "moment": "^2.14.1", + "steemauth": "0.0.4", "ws": "^1.1.1" }, "devDependencies": { diff --git a/test.js b/test.js index 5a37f7b2a253a101a93364e9229acd444dbc5d03..f98d58ab6dc15fad6bd99313ad987d282b4cb56f 100644 --- a/test.js +++ b/test.js @@ -1,29 +1,8 @@ var steem = require('./index'); -steem.api.getAccountCount(function(err, result) { - console.log(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.api.getFollowing('ned', 0, 'blog', 10, function(err, result) { - console.log(err, result); -}); +var username = process.env.STEEM_USERNAME; +var password = process.env.STEEM_PASSWORD; -steem.api.getFollowers('dan', 0, 'blog', 10, function(err, result) { +steem.broadcast.vote(username, password, 'infovore', 'mentorship-channel-for-artists-this-week-on-steemit-steemians-speak-behind-the-username-steemmag-steemit-s-weekend-digest-6-p-2', 10000, function(err, result) { console.log(err, result); -}); - -steem.api.streamOperations(function(err, result) { - if (!err && result[1].author == 'fabien') { - console.log(result); - } }); \ No newline at end of file