flatten out directory structure
This commit is contained in:
parent
a91b3474e9
commit
aec981d0fe
62
commands.js
Normal file
62
commands.js
Normal file
@ -0,0 +1,62 @@
|
||||
module.exports = {
|
||||
addMultiSigAddress: 'addmultisigaddress',
|
||||
addNode: 'addnode', // bitcoind v0.8.0+
|
||||
backupWallet: 'backupwallet',
|
||||
createRawTransaction: 'createrawtransaction', // bitcoind v0.7.0+
|
||||
decodeRawTransaction: 'decoderawtransaction', // bitcoind v0.7.0+
|
||||
dumpPrivKey: 'dumpprivkey',
|
||||
encryptWallet: 'encryptwallet',
|
||||
getAccount: 'getaccount',
|
||||
getAccountAddress: 'getaccountaddress',
|
||||
getAddedNodeInfo: 'getaddednodeinfo', // bitcoind v0.8.0+
|
||||
getAddressesByAccount: 'getaddressesbyaccount',
|
||||
getBalance: 'getbalance',
|
||||
getBlock: 'getblock',
|
||||
getBlockCount: 'getblockcount',
|
||||
getBlockHash: 'getblockhash',
|
||||
getConnectionCount: 'getconnectioncount',
|
||||
getDifficulty: 'getdifficulty',
|
||||
getGenerate: 'getgenerate',
|
||||
getHashesPerSecond: 'gethashespersec',
|
||||
getHashesPerSec: 'gethashespersec',
|
||||
getInfo: 'getinfo',
|
||||
getMemorypool: 'getmemorypool',
|
||||
getMemoryPool: 'getmemorypool',
|
||||
getMiningInfo: 'getmininginfo',
|
||||
getNewAddress: 'getnewaddress',
|
||||
getPeerInfo: 'getpeerinfo', // bitcoind v0.7.0+
|
||||
getRawMemPool: 'getrawmempool', // bitcoind v0.7.0+
|
||||
getRawTransaction: 'getrawtransaction', // bitcoind v0.7.0+
|
||||
getReceivedByAccount: 'getreceivedbyaccount',
|
||||
getReceivedByAddress: 'getreceivedbyaddress',
|
||||
getTransaction: 'gettransaction',
|
||||
getWork: 'getwork',
|
||||
help: 'help',
|
||||
importPrivKey: 'importprivkey',
|
||||
keypoolRefill: 'keypoolrefill',
|
||||
keyPoolRefill: 'keypoolrefill',
|
||||
listAccounts: 'listaccounts',
|
||||
listLockUnspent: 'listlockunspent', // bitcoind v0.8.0
|
||||
listReceivedByAccount: 'listreceivedbyaccount',
|
||||
listReceivedByAddress: 'listreceivedbyaddress',
|
||||
listSinceBlock: 'listsinceblock',
|
||||
listTransactions: 'listtransactions',
|
||||
listUnspent: 'listunspent', // bitcoind v0.7.0+
|
||||
lockUnspent: 'lockunspent', // bitcoind v0.8.0+
|
||||
move: 'move',
|
||||
sendFrom: 'sendfrom',
|
||||
sendMany: 'sendmany',
|
||||
sendRawTransaction: 'sendrawtransaction', // bitcoind v0.7.0+
|
||||
sendToAddress: 'sendtoaddress',
|
||||
setAccount: 'setaccount',
|
||||
setGenerate: 'setgenerate',
|
||||
setTxFee: 'settxfee',
|
||||
signMessage: 'signmessage',
|
||||
signRawTransaction: 'signrawtransaction', // bitcoind v0.7.0+
|
||||
stop: 'stop',
|
||||
validateAddress: 'validateaddress',
|
||||
verifyMessage: 'verifymessage',
|
||||
walletLock: 'walletlock',
|
||||
walletPassphrase: 'walletpassphrase',
|
||||
walletPassphraseChange: 'walletpassphrasechange'
|
||||
};
|
||||
85
index.js
Normal file
85
index.js
Normal file
@ -0,0 +1,85 @@
|
||||
var deprecate = require('deprecate'),
|
||||
commands = require('./commands'),
|
||||
rpc = require('./jsonrpc');
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Client
|
||||
// Pass in an object with host, port, user, pass
|
||||
//===----------------------------------------------------------------------===//
|
||||
function Client() {
|
||||
var args = [].slice.call(arguments);
|
||||
|
||||
if (args.length > 1) {
|
||||
deprecate('calling bitcoin.Client with more than one argument is deprecated');
|
||||
this.host = args[0];
|
||||
this.port = args[1];
|
||||
this.user = args[2];
|
||||
this.pass = args[3];
|
||||
this.ssl = false;
|
||||
this.sslStrict = false;
|
||||
this.sslCa = null;
|
||||
} else {
|
||||
this.host = args[0].host;
|
||||
this.port = args[0].port;
|
||||
this.user = args[0].user;
|
||||
this.pass = args[0].pass;
|
||||
this.ssl = args[0].ssl ? true : false;
|
||||
this.sslStrict = (typeof args[0].sslStrict === 'undefined' || args[0].sslStrict);
|
||||
this.sslCa = args[0].sslCa;
|
||||
}
|
||||
|
||||
this.rpc = new rpc.Client(this.port, this.host, this.user, this.pass,
|
||||
this.ssl, this.sslStrict, this.sslCa);
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// cmd
|
||||
// Call custom jsonrpc commands
|
||||
//===----------------------------------------------------------------------===//
|
||||
Client.prototype.cmd = function() {
|
||||
var args = [].slice.call(arguments);
|
||||
var cmd = args.shift();
|
||||
|
||||
callRpc(cmd, args, this.rpc);
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// callRpc
|
||||
//===----------------------------------------------------------------------===//
|
||||
function callRpc(cmd, args, rpc) {
|
||||
var fn = args[args.length-1];
|
||||
|
||||
// If the last function is a callback, pop it from the args list
|
||||
if(typeof fn === 'function') {
|
||||
args.pop();
|
||||
} else {
|
||||
fn = function () {};
|
||||
}
|
||||
|
||||
rpc.call(cmd, args, function(){
|
||||
var args = [].slice.call(arguments);
|
||||
args.unshift(null);
|
||||
fn.apply(this, args);
|
||||
}, function(err){
|
||||
fn(err);
|
||||
});
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Initialize wrappers
|
||||
//===----------------------------------------------------------------------===//
|
||||
(function() {
|
||||
for (var protoFn in commands) {
|
||||
(function(protoFn) {
|
||||
Client.prototype[protoFn] = function() {
|
||||
var args = [].slice.call(arguments);
|
||||
callRpc(commands[protoFn], args, this.rpc);
|
||||
};
|
||||
})(protoFn);
|
||||
}
|
||||
})();
|
||||
|
||||
// Export!
|
||||
module.exports.Client = Client;
|
||||
@ -1,152 +0,0 @@
|
||||
var rpc = require('../jsonrpc'),
|
||||
deprecate = require('deprecate');
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// jsonrpc wrappers
|
||||
//===----------------------------------------------------------------------===//
|
||||
var bitcoinAPI = {
|
||||
addMultiSigAddress: 'addmultisigaddress',
|
||||
addNode: 'addnode', // bitcoind v0.8.0+
|
||||
backupWallet: 'backupwallet',
|
||||
createRawTransaction: 'createrawtransaction', // bitcoind v0.7.0+
|
||||
decodeRawTransaction: 'decoderawtransaction', // bitcoind v0.7.0+
|
||||
dumpPrivKey: 'dumpprivkey',
|
||||
encryptWallet: 'encryptwallet',
|
||||
getAccount: 'getaccount',
|
||||
getAccountAddress: 'getaccountaddress',
|
||||
getAddedNodeInfo: 'getaddednodeinfo', // bitcoind v0.8.0+
|
||||
getAddressesByAccount: 'getaddressesbyaccount',
|
||||
getBalance: 'getbalance',
|
||||
getBlock: 'getblock',
|
||||
getBlockCount: 'getblockcount',
|
||||
getBlockHash: 'getblockhash',
|
||||
getConnectionCount: 'getconnectioncount',
|
||||
getDifficulty: 'getdifficulty',
|
||||
getGenerate: 'getgenerate',
|
||||
getHashesPerSecond: 'gethashespersec',
|
||||
getHashesPerSec: 'gethashespersec',
|
||||
getInfo: 'getinfo',
|
||||
getMemorypool: 'getmemorypool',
|
||||
getMemoryPool: 'getmemorypool',
|
||||
getMiningInfo: 'getmininginfo',
|
||||
getNewAddress: 'getnewaddress',
|
||||
getPeerInfo: 'getpeerinfo', // bitcoind v0.7.0+
|
||||
getRawMemPool: 'getrawmempool', // bitcoind v0.7.0+
|
||||
getRawTransaction: 'getrawtransaction', // bitcoind v0.7.0+
|
||||
getReceivedByAccount: 'getreceivedbyaccount',
|
||||
getReceivedByAddress: 'getreceivedbyaddress',
|
||||
getTransaction: 'gettransaction',
|
||||
getWork: 'getwork',
|
||||
help: 'help',
|
||||
importPrivKey: 'importprivkey',
|
||||
keypoolRefill: 'keypoolrefill',
|
||||
keyPoolRefill: 'keypoolrefill',
|
||||
listAccounts: 'listaccounts',
|
||||
listLockUnspent: 'listlockunspent', // bitcoind v0.8.0
|
||||
listReceivedByAccount: 'listreceivedbyaccount',
|
||||
listReceivedByAddress: 'listreceivedbyaddress',
|
||||
listSinceBlock: 'listsinceblock',
|
||||
listTransactions: 'listtransactions',
|
||||
listUnspent: 'listunspent', // bitcoind v0.7.0+
|
||||
lockUnspent: 'lockunspent', // bitcoind v0.8.0+
|
||||
move: 'move',
|
||||
sendFrom: 'sendfrom',
|
||||
sendMany: 'sendmany',
|
||||
sendRawTransaction: 'sendrawtransaction', // bitcoind v0.7.0+
|
||||
sendToAddress: 'sendtoaddress',
|
||||
setAccount: 'setaccount',
|
||||
setGenerate: 'setgenerate',
|
||||
setTxFee: 'settxfee',
|
||||
signMessage: 'signmessage',
|
||||
signRawTransaction: 'signrawtransaction', // bitcoind v0.7.0+
|
||||
stop: 'stop',
|
||||
validateAddress: 'validateaddress',
|
||||
verifyMessage: 'verifymessage',
|
||||
walletLock: 'walletlock',
|
||||
walletPassphrase: 'walletpassphrase',
|
||||
walletPassphraseChange: 'walletpassphrasechange'
|
||||
};
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Client
|
||||
// Pass in an object with host, port, user, pass
|
||||
//===----------------------------------------------------------------------===//
|
||||
function Client() {
|
||||
var args = [].slice.call(arguments);
|
||||
|
||||
if (args.length > 1) {
|
||||
deprecate('calling bitcoin.Client with more than one argument is deprecated');
|
||||
this.host = args[0];
|
||||
this.port = args[1];
|
||||
this.user = args[2];
|
||||
this.pass = args[3];
|
||||
this.ssl = false;
|
||||
this.sslStrict = false;
|
||||
this.sslCa = null;
|
||||
} else {
|
||||
this.host = args[0].host;
|
||||
this.port = args[0].port;
|
||||
this.user = args[0].user;
|
||||
this.pass = args[0].pass;
|
||||
this.ssl = args[0].ssl ? true : false;
|
||||
this.sslStrict = (typeof args[0].sslStrict === 'undefined' || args[0].sslStrict);
|
||||
this.sslCa = args[0].sslCa;
|
||||
}
|
||||
|
||||
this.rpc = new rpc.Client(this.port, this.host, this.user, this.pass,
|
||||
this.ssl, this.sslStrict, this.sslCa);
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// cmd
|
||||
// Call custom jsonrpc commands
|
||||
//===----------------------------------------------------------------------===//
|
||||
Client.prototype.cmd = function() {
|
||||
var args = [].slice.call(arguments);
|
||||
var cmd = args.shift();
|
||||
|
||||
callRpc(cmd, args, this.rpc);
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// callRpc
|
||||
//===----------------------------------------------------------------------===//
|
||||
function callRpc(cmd, args, rpc) {
|
||||
var fn = args[args.length-1];
|
||||
|
||||
// If the last function is a callback, pop it from the args list
|
||||
if(typeof fn === 'function') {
|
||||
args.pop();
|
||||
} else {
|
||||
fn = function () {};
|
||||
}
|
||||
|
||||
rpc.call(cmd, args, function(){
|
||||
var args = [].slice.call(arguments);
|
||||
args.unshift(null);
|
||||
fn.apply(this, args);
|
||||
}, function(err){
|
||||
fn(err);
|
||||
});
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Initialize wrappers
|
||||
//===----------------------------------------------------------------------===//
|
||||
(function() {
|
||||
for (var protoFn in bitcoinAPI) {
|
||||
(function(protoFn) {
|
||||
Client.prototype[protoFn] = function() {
|
||||
var args = [].slice.call(arguments);
|
||||
callRpc(bitcoinAPI[protoFn], args, this.rpc);
|
||||
};
|
||||
})(protoFn);
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
// Export!
|
||||
module.exports = Client;
|
||||
@ -1,2 +0,0 @@
|
||||
|
||||
module.exports.Client = require('./client');
|
||||
@ -2,7 +2,7 @@
|
||||
"name": "bitcoin",
|
||||
"description": "Communicate with bitcoind via JSON-RPC",
|
||||
"version": "1.6.0",
|
||||
"main": "./lib/bitcoin",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"rpc"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
var assert = require('assert'),
|
||||
bitcoin = require('../lib/bitcoin'),
|
||||
bitcoin = require('../'),
|
||||
config = require('./config'),
|
||||
deprecate = require('deprecate');
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
clone = require('clone'),
|
||||
bitcoin = require('../lib/bitcoin'),
|
||||
bitcoin = require('../'),
|
||||
config = require('./config');
|
||||
|
||||
var getInfo = function(opts, cb) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user