-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c55f4a0
Showing
16 changed files
with
653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"stage": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
; editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.json] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "standard", | ||
"parser": "babel-eslint", | ||
"env": { | ||
"node": true, | ||
"mocha": true, | ||
"es6": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coverage | ||
lib | ||
node_modules | ||
test/config/bitcoind.json | ||
|
||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
language: node_js | ||
node_js: | ||
- "0.10" | ||
- "0.12" | ||
before_script: | ||
- cp test/config/bitcoind.json.travis test/config/bitcoind.json | ||
- mkdir -p ~/.bitcoin | ||
- cp test/config/bitcoin.conf.travis ~/.bitcoin/bitcoin.conf | ||
- wget https://bitcoin.org/bin/bitcoin-core-0.11.0/bitcoin-0.11.0-linux64.tar.gz | ||
- tar -xf bitcoin-0.11.0-linux64.tar.gz | ||
- ./bitcoin-0.11.0/bin/bitcoind -testnet -server -daemon | ||
- sleep 15 | ||
install: | ||
- npm install | ||
env: | ||
- TEST_SUITE=coveralls | ||
- TEST_SUITE=lint | ||
script: "npm run $TEST_SUITE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Kirill Fomichev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
Bitcoind RPC client with blackjack and hookers. | ||
|
||
Current rpc client support promises and callbacks. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install bitcoind-rpc-client | ||
``` | ||
|
||
## Commands | ||
|
||
You can find list of all available commands in [source code](blob/master/src/methods.js). | ||
|
||
## Examples | ||
|
||
### Create client | ||
|
||
```js | ||
var client = new RpcClient({ | ||
host: '127.0.0.1', | ||
port: 18332 | ||
}); | ||
client.set('user', 'bitcoinrpc') | ||
``` | ||
|
||
### getnewaddress with callback | ||
|
||
```js | ||
client.getNewAddress(function (err, result) { | ||
console.log(err, result) // null, {result: {...}, error: null} | ||
}) | ||
``` | ||
|
||
### getnewaddress with promise | ||
|
||
```js | ||
client.getNewAddress().then(function (result) { | ||
console.log(result) // {result: {...}, error: null} | ||
}) | ||
``` | ||
|
||
### alias of getnewaddress with promise | ||
|
||
```js | ||
client.getnewaddress().then(function (result) { | ||
console.log(result) // {result: {...}, error: null} | ||
}) | ||
``` | ||
|
||
### getnewaddress using `cmd` | ||
|
||
```js | ||
client.cmd('getnewaddress').then(function (result) { | ||
console.log(result) // {result: {...}, error: null} | ||
}) | ||
``` | ||
|
||
### batch (array form) | ||
|
||
```js | ||
client.batch([ | ||
{method: 'getnewaddress', params: ['myaccount']}, | ||
{method: 'getnewaddress', params: ['myaccount']} | ||
]) | ||
.then(function (result) { | ||
console.log(result) // [{result: {...}, error: null}, {result: {...}, error: null}] | ||
}) | ||
``` | ||
|
||
### batch (chained form) | ||
|
||
```js | ||
client.batch() | ||
.getInfo() | ||
.clear() | ||
.getNewAddress('myaccount') | ||
.getNewAddress('secondaccount') | ||
.call() | ||
.then(function (result) { | ||
console.log(result) // [{result: {...}, error: null}, {result: {...}, error: null}] | ||
}) | ||
``` | ||
|
||
## License | ||
|
||
Code released under [the MIT license](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "bitcoind-rpc-client", | ||
"version": "0.1.0", | ||
"description": "Bitcoind RPC client", | ||
"keywords": [ | ||
"bitcoin", | ||
"bitcoind", | ||
"rpc" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/fanatid/bitcoind-rpc-client/issues" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Kirill Fomichev", | ||
"email": "fanatid@ya.ru" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"main": "./lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fanatid/bitcoind-rpc-client" | ||
}, | ||
"scripts": { | ||
"prepublish": "npm run clean && npm run compile", | ||
"clean": "rm -f lib/*", | ||
"compile": "mkdir -p lib && babel src -d lib --optional runtime -s true", | ||
"coverage": "istanbul cover _mocha -- --compilers js:babel/register test/*.js", | ||
"coveralls": "npm run coverage && coveralls <coverage/lcov.info", | ||
"lint": "eslint src test", | ||
"test": "istanbul test mocha -- --compilers js:babel/register --reporter spec test/*.js", | ||
"watch:src": "mkdir -p lib && babel src -d lib --optional runtime -s true -w" | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^5.8.20" | ||
}, | ||
"devDependencies": { | ||
"babel": "^5.8.21", | ||
"babel-eslint": "^4.0.10", | ||
"chai": "^3.2.0", | ||
"coveralls": "^2.11.4", | ||
"eslint": "^1.2.0", | ||
"eslint-config-standard": "^4.1.0", | ||
"eslint-plugin-standard": "^1.2.0", | ||
"istanbul": "^0.3.18", | ||
"mocha": "^2.2.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Methods from './methods' | ||
|
||
/** | ||
* @class BatchInterface | ||
*/ | ||
export default class BatchInterface extends Methods { | ||
/** | ||
* @constructor | ||
* @param {RpcClient} bitcoind | ||
*/ | ||
constructor (bitcoind) { | ||
super() | ||
|
||
this._bitcoind = bitcoind | ||
|
||
this._isCalled = false | ||
this._batch = [] | ||
} | ||
|
||
/** | ||
*/ | ||
_isCalledCheck () { | ||
if (this._isCalled) { | ||
throw new Error('batch was already called!') | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} method | ||
* @return {BatchInterface} | ||
*/ | ||
cmd (method, ...params) { | ||
this._isCalledCheck() | ||
this._batch.push({method: method, params: params}) | ||
return this | ||
} | ||
|
||
/** | ||
* @return {BatchInterface} | ||
*/ | ||
clear () { | ||
this._isCalledCheck() | ||
this._batch = [] | ||
return this | ||
} | ||
|
||
/** | ||
* @param {function} [callback] | ||
* @return {Promise.<Array.<{error: ?{code: number, message: string}, result: *}>>} | ||
*/ | ||
call (callback) { | ||
this._isCalledCheck() | ||
this._isCalled = true | ||
return this._bitcoind.batch(this._batch, callback) | ||
} | ||
} |
Oops, something went wrong.