bitcore-node-zcash/lib/bitcoind.js

805 lines
18 KiB
JavaScript
Raw Normal View History

2014-08-12 12:03:04 -07:00
/**
* bitcoind.js
* Copyright (c) 2014, BitPay (MIT License)
* A bitcoind node.js binding.
*/
var net = require('net');
var EventEmitter = require('events').EventEmitter;
var bitcoindjs = require('../build/Release/bitcoindjs.node');
2014-09-02 19:28:20 -07:00
var util = require('util');
2014-10-16 13:53:47 -07:00
var fs = require('fs');
var mkdirp = require('mkdirp');
2014-08-12 12:03:04 -07:00
/**
* Bitcoin
*/
2014-09-25 13:39:06 -07:00
var bitcoin = Bitcoin;
2014-08-29 13:54:54 -07:00
function Bitcoin(options) {
2014-08-12 12:03:04 -07:00
var self = this;
if (!(this instanceof Bitcoin)) {
2014-08-29 13:54:54 -07:00
return new Bitcoin(options);
2014-08-12 12:03:04 -07:00
}
EventEmitter.call(this);
2014-10-16 13:53:47 -07:00
this.options = options || {};
this.wallet = Wallet;
2014-09-25 13:58:54 -07:00
2014-10-16 13:53:47 -07:00
if (typeof this.options === 'string') {
this.options = { datadir: this.options };
}
if (this.options.directory) {
this.options.datadir = this.options.directory;
delete this.options.directory;
}
if (!this.options.datadir) {
this.options.datadir = process.env.HOME + '/.bitcoin';
}
2014-10-16 13:53:47 -07:00
this.options.datadir = this.options.datadir.replace(/^~/, process.env.HOME);
this.config = this.options.datadir + '/bitcoin.conf';
if (this.instances[this.options.datadir]) {
throw new Error(''
+ 'bitcoind.js cannot be instantiated'
+ ' more than once on the same datadir.');
}
2014-10-16 13:53:47 -07:00
if (!fs.existsSync(this.options.datadir)) {
mkdirp.sync(this.options.datadir);
}
if (!fs.existsSync(this.config)) {
var password = ''
+ Math.random().toString(36).slice(2)
2014-10-16 13:53:47 -07:00
+ Math.random().toString(36).slice(2)
+ Math.random().toString(36).slice(2);
fs.writeFileSync(this.config, ''
+ 'rpcuser=bitcoinrpc\n'
+ 'rpcpassword=' + password + '\n'
);
}
2014-10-03 18:27:06 -07:00
Object.keys(exports).forEach(function(key) {
self[key] = exports[key];
});
2014-09-25 14:28:08 -07:00
this.on('newListener', function(name) {
if (name === 'open') {
self.start();
}
});
2014-09-11 17:18:36 -07:00
}
Bitcoin.prototype.__proto__ = EventEmitter.prototype;
// Make sure signal handlers are not overwritten
Bitcoin._signalQueue = [];
Bitcoin._processOn = process.on;
process.addListener =
process.on = function(name, listener) {
if (~['SIGINT', 'SIGHUP', 'SIGQUIT'].indexOf(name.toUpperCase())) {
if (!Bitcoin.global || !Bitcoin.global._started) {
Bitcoin._signalQueue.push([name, listener]);
return;
}
}
2014-09-30 15:53:13 -07:00
return Bitcoin._processOn.apply(this, arguments);
};
Bitcoin.instances = {};
Bitcoin.prototype.instances = Bitcoin.instances;
Bitcoin.__defineGetter__('global', function() {
return Bitcoin.instances[process.env.HOME + '/.bitcoin'];
});
2014-10-15 16:38:10 -07:00
Bitcoin.prototype.start = function(options, callback) {
2014-09-11 17:18:36 -07:00
var self = this;
2014-08-29 13:54:54 -07:00
2014-10-15 16:38:10 -07:00
if (!callback) {
callback = options;
2014-10-16 13:53:47 -07:00
options = null;
}
if (!options) {
2014-10-15 16:38:10 -07:00
options = {};
}
2014-10-16 13:53:47 -07:00
2014-10-15 16:38:10 -07:00
if (!callback) {
callback = utils.NOOP;
}
if (this.instances[this.options.datadir]) {
return;
}
this.instances[this.options.datadir] = true;
2014-09-25 14:28:08 -07:00
2014-09-17 14:21:28 -07:00
var none = {};
2014-09-22 14:35:11 -07:00
var isSignal = {};
var sigint = { name: 'SIGINT', signal: isSignal };
var sighup = { name: 'SIGHUP', signal: isSignal };
var sigquit = { name: 'SIGQUIT', signal: isSignal };
2014-09-17 14:21:28 -07:00
var exitCaught = none;
var errorCaught = none;
2014-10-16 13:53:47 -07:00
Object.keys(this.options).forEach(function(key) {
if (options[key] == null) {
options[key] = self.options[key];
}
});
2014-10-15 16:38:10 -07:00
this.log_pipe = bitcoindjs.start(options, function(err, status) {
self._started = true;
2014-09-22 14:35:11 -07:00
[sigint, sighup, sigquit].forEach(function(signal) {
process.on(signal.name, signal.listener = function() {
if (process.listeners(signal.name).length > 1) {
return;
}
if (!self._shutdown) {
process.exit(0);
} else {
self.stop();
exitCaught = signal;
}
});
2014-09-19 16:45:46 -07:00
});
2014-09-17 14:21:28 -07:00
// Finally set signal handlers
2014-09-30 15:53:13 -07:00
process.on = process.addListener = Bitcoin._processOn;
Bitcoin._signalQueue.forEach(function(event) {
process.on(event[0], event[1]);
});
2014-09-17 14:21:28 -07:00
var exit = process.exit;
self._exit = function() {
return exit.apply(process, arguments);
};
process.exit = function(code) {
exitCaught = code || 0;
if (!self._shutdown) {
return self._exit(code);
2014-09-17 14:21:28 -07:00
}
self.stop();
};
2014-09-17 14:08:26 -07:00
2014-09-17 14:21:28 -07:00
process.on('uncaughtException', function(err) {
if (process.listeners('uncaughtException').length > 1) {
return;
}
2014-09-17 14:21:28 -07:00
errorCaught = err;
2014-09-25 13:39:06 -07:00
self.error('Uncaught error: shutting down safely before throwing...');
2014-09-17 14:21:28 -07:00
if (!self._shutdown) {
if (err && err.stack) {
console.error(err.stack);
}
self._exit(1);
return;
2014-09-17 14:21:28 -07:00
}
self.stop();
});
2014-09-17 14:25:19 -07:00
setTimeout(function callee() {
// Wait until wallet is loaded:
if (!Object.keys(self.wallet.listAccounts()).length) {
return setTimeout(callee, 100);
}
2014-09-17 14:25:19 -07:00
if (callback) {
callback(err ? err : null);
}
if (err) {
self.emit('error', err);
} else {
if (callback) {
self.emit('open', status);
} else {
self.emit('status', status);
}
}
if (callback) {
callback = null;
}
}, 100);
2014-08-12 12:03:04 -07:00
});
2014-09-02 19:28:20 -07:00
2014-09-10 16:57:18 -07:00
// bitcoind's boost threads aren't in the thread pool
// or on node's event loop, so we need to keep node open.
2014-09-17 14:08:26 -07:00
this._shutdown = setInterval(function() {
if (!self._stoppingSaid && bitcoindjs.stopping()) {
self._stoppingSaid = true;
self.log('shutting down...');
}
2014-09-17 14:21:28 -07:00
2014-09-17 12:52:35 -07:00
if (bitcoindjs.stopped()) {
2014-09-17 14:08:26 -07:00
self.log('shut down.');
2014-09-17 14:21:28 -07:00
2014-09-17 14:08:26 -07:00
clearInterval(self._shutdown);
delete self._shutdown;
2014-09-17 14:21:28 -07:00
if (exitCaught !== none) {
2014-09-22 14:35:11 -07:00
if (exitCaught.signal === isSignal) {
process.removeListener(exitCaught.name, exitCaught.listener);
setImmediate(function() {
process.kill(process.pid, exitCaught.name);
});
return;
}
2014-09-19 16:45:46 -07:00
return self._exit(exitCaught);
2014-09-17 14:21:28 -07:00
}
if (errorCaught !== none) {
if (errorCaught && errorCaught.stack) {
2014-09-17 14:21:28 -07:00
console.error(errorCaught.stack);
}
return self._exit(0);
}
2014-09-17 12:52:35 -07:00
}
2014-09-17 14:08:26 -07:00
}, 1000);
2014-09-10 16:57:18 -07:00
2014-09-22 18:21:08 -07:00
this.pollInterval = 300;
2014-09-22 18:34:38 -07:00
this._emitted = {};
2014-09-23 13:57:49 -07:00
this.on('newListener', function(name) {
if (name === 'block') {
self._pollBlocks();
return;
}
if (name === 'tx') {
self._pollBlocks();
self._pollMempool();
return;
}
if (name === 'mptx') {
self._pollMempool();
return;
}
});
if (this.log_pipe !== -1) {
this.log('log pipe opened: %d', this.log_pipe);
this._pipe = new net.Socket(this.log_pipe);
this._pipe.on('data', function(data) {
2014-09-25 15:25:12 -07:00
return process.stdout.write('bitcoind.js: ' + data + '\n');
2014-09-23 13:57:49 -07:00
});
this._pipe.on('error', function(err) {
; // ignore for now
});
this._pipe.resume();
}
};
Bitcoin.prototype._pollBlocks = function() {
2014-09-23 14:01:10 -07:00
var self = this;
2014-09-23 13:57:49 -07:00
if (this._pollingBlocks) return;
this._pollingBlocks = true;
2014-09-22 17:58:59 -07:00
(function next() {
2014-09-23 10:21:44 -07:00
return bitcoindjs.pollBlocks(function(err, blocks) {
2014-10-01 12:05:18 -07:00
if (err) {
if (self.debug) {
console.log('poll error:');
console.log(err.message);
}
return setTimeout(next, self.pollInterval);
}
2014-09-23 10:21:44 -07:00
return utils.forEach(blocks, function(block, nextBlock) {
2014-09-25 13:45:42 -07:00
block = bitcoin.block(block);
2014-09-22 18:34:38 -07:00
// XXX Bad workaround
2014-09-23 10:21:44 -07:00
if (self._emitted[block.hash]) {
return setImmediate(function() {
return nextBlock();
});
}
self._emitted[block.hash] = true;
2014-09-22 17:58:59 -07:00
self.emit('block', block);
2014-09-23 10:21:44 -07:00
2014-10-01 12:05:18 -07:00
if (!self._pollingTxs) {
return setImmediate(function() {
return nextBlock();
});
}
2014-09-23 11:17:25 -07:00
return utils.forEach(block.tx, function(tx, nextTx) {
2014-09-25 13:50:47 -07:00
tx = bitcoin.tx(tx);
2014-09-23 11:17:25 -07:00
self.emit('tx', tx);
return setImmediate(function() {
return nextTx();
});
}, function() {
return setImmediate(function() {
return nextBlock();
});
2014-09-22 18:21:08 -07:00
});
}, function() {
2014-10-01 12:05:18 -07:00
if (self.debug) {
console.log('emission finished');
}
2014-09-23 10:21:44 -07:00
return setTimeout(next, self.pollInterval);
2014-09-22 17:58:59 -07:00
});
});
})();
2014-09-23 13:57:49 -07:00
};
2014-09-22 16:36:36 -07:00
2014-09-23 13:57:49 -07:00
Bitcoin.prototype._pollMempool = function() {
2014-09-23 14:01:10 -07:00
var self = this;
2014-10-01 12:05:18 -07:00
if (this._pollingTxs) return;
this._pollingTxs = true;
2014-09-23 13:57:49 -07:00
(function next() {
return bitcoindjs.pollMempool(function(err, txs) {
if (err) return setTimeout(next, self.pollInterval);
return utils.forEach(txs, function(tx, nextTx) {
2014-09-25 13:45:42 -07:00
tx = bitcoin.tx(tx);
2014-09-23 13:57:49 -07:00
// XXX Bad workaround
2014-10-02 20:18:37 -07:00
if (self._emitted[tx.txid]) {
2014-09-23 13:57:49 -07:00
return setImmediate(function() {
return nextTx();
});
}
2014-10-02 20:18:37 -07:00
self._emitted[tx.txid] = true;
2014-09-23 13:57:49 -07:00
self.emit('mptx', tx);
self.emit('tx', tx);
return setImmediate(function() {
return nextTx();
});
}, function() {
return setTimeout(next, self.pollInterval);
});
2014-09-17 15:33:21 -07:00
});
2014-09-23 13:57:49 -07:00
})();
2014-09-11 17:18:36 -07:00
};
2014-08-12 12:03:04 -07:00
2014-09-22 12:27:33 -07:00
Bitcoin.prototype.getBlock = function(blockHash, callback) {
2014-09-25 13:45:42 -07:00
return bitcoindjs.getBlock(blockHash, function(err, block) {
if (err) return callback(err);
2014-09-25 15:25:12 -07:00
return callback(null, bitcoin.block(block));
2014-09-25 13:45:42 -07:00
});
2014-09-18 17:14:17 -07:00
};
2014-09-22 12:27:33 -07:00
Bitcoin.prototype.getTx = function(txHash, blockHash, callback) {
if (!callback) {
callback = blockHash;
blockHash = '';
}
2014-09-25 13:45:42 -07:00
return bitcoindjs.getTx(txHash, blockHash, function(err, tx) {
if (err) return callback(err);
2014-09-25 15:25:12 -07:00
return callback(null, bitcoin.tx(tx));
2014-09-25 13:45:42 -07:00
});
2014-09-22 12:05:17 -07:00
};
2014-09-02 19:28:20 -07:00
Bitcoin.prototype.log =
Bitcoin.prototype.info = function() {
if (typeof arguments[0] !== 'string') {
var out = util.inspect(arguments[0], null, 20, true);
2014-09-17 14:31:20 -07:00
return process.stdout.write('bitcoind.js: ' + out + '\n');
2014-09-02 19:28:20 -07:00
}
var out = util.format.apply(util, arguments);
2014-09-17 14:31:20 -07:00
return process.stdout.write('bitcoind.js: ' + out + '\n');
2014-09-02 19:28:20 -07:00
};
Bitcoin.prototype.error = function() {
if (typeof arguments[0] !== 'string') {
var out = util.inspect(arguments[0], null, 20, true);
2014-09-17 14:31:20 -07:00
return process.stderr.write('bitcoind.js: ' + out + '\n');
2014-09-02 19:28:20 -07:00
}
var out = util.format.apply(util, arguments);
2014-09-17 14:31:20 -07:00
return process.stderr.write('bitcoind.js: ' + out + '\n');
2014-09-02 19:28:20 -07:00
};
2014-09-11 17:18:36 -07:00
Bitcoin.prototype.stop =
Bitcoin.prototype.close = function(callback) {
var self = this;
return bitcoindjs.stop(function(err, status) {
if (err) {
self.error(err.message);
} else {
self.log(status);
}
if (!callback) return;
return callback(err, status);
});
2014-09-10 16:57:18 -07:00
};
2014-09-02 19:28:20 -07:00
2014-09-25 10:59:36 -07:00
/**
* Block
*/
function Block(data) {
if (!(this instanceof Block)) {
return new Block(data);
}
2014-09-25 13:39:06 -07:00
if (data instanceof Block) {
return data;
}
2014-09-25 13:45:42 -07:00
var self = this;
Object.keys(data).forEach(function(key) {
2014-09-25 14:12:09 -07:00
if (!self[key]) {
self[key] = data[key];
}
2014-09-25 13:45:42 -07:00
});
2014-09-26 11:39:25 -07:00
this.tx = this.tx.map(function(tx) {
return bitcoin.tx(tx);
});
2014-09-29 16:06:49 -07:00
if (!this.hex) {
this.hex = this.toHex();
}
2014-09-25 10:59:36 -07:00
}
Object.defineProperty(Block.prototype, '_blockFlag', {
__proto__: null,
configurable: false,
enumerable: false,
writable: false,
2014-10-06 08:10:23 -07:00
value: {}
});
2014-09-29 14:38:52 -07:00
Block.isBlock = function(block) {
2014-10-06 08:10:23 -07:00
return block._blockFlag === Block.prototype._blockFlag;
2014-09-29 14:38:52 -07:00
};
2014-10-03 18:27:06 -07:00
Block.fromHex = function(hex) {
return bitcoin.block(bitcoindjs.blockFromHex(hex));
};
Block.prototype.getHash = function(enc) {
var data = bitcoindjs.getBlockHex(this);
if (!this.hash || this.hash !== data.hash) {
this.hash = data.hash;
}
2014-10-03 16:39:26 -07:00
if (enc === 'hex') return data.hash;
var buf = new Buffer(data.hash, 'hex');
var out = enc ? buf.toString(enc) : buf;
return out;
};
2014-09-26 11:23:21 -07:00
Block.prototype.verify = function() {
2014-09-26 11:39:25 -07:00
return this.verified = this.verified || bitcoindjs.verifyBlock(this);
2014-09-26 11:23:21 -07:00
};
Block.prototype.toHex = function() {
var hex = Block.toHex(this);
if (!this.hex || this.hex !== hex) {
this.hex = hex;
}
return hex;
};
Block.toHex = function(block) {
var data = bitcoindjs.getBlockHex(block);
return data.hex;
};
2014-09-26 11:23:21 -07:00
Block.prototype.toBinary = function() {
return Block.toBinary(this);
};
Block.toBinary = function(block) {
var data = bitcoindjs.getBlockHex(block);
return new Buffer(data.hex, 'hex');
};
2014-09-25 10:59:36 -07:00
/**
* Transaction
*/
function Transaction(data) {
if (!(this instanceof Transaction)) {
return new Transaction(data);
}
2014-09-25 13:39:06 -07:00
if (data instanceof Transaction) {
return data;
}
var self = this;
Object.keys(data).forEach(function(key) {
2014-09-25 14:12:09 -07:00
if (!self[key]) {
self[key] = data[key];
}
2014-09-25 13:39:06 -07:00
});
2014-09-25 14:12:09 -07:00
if (!this.hex) {
this.hex = this.toHex();
}
2014-09-25 10:59:36 -07:00
}
Object.defineProperty(Transaction.prototype, '_txFlag', {
__proto__: null,
configurable: false,
enumerable: false,
writable: false,
2014-10-06 08:10:23 -07:00
value: {}
});
2014-09-29 14:38:52 -07:00
Transaction.isTransaction =
Transaction.isTx = function(tx) {
2014-10-06 08:10:23 -07:00
return tx._txFlag === Transaction.prototype._txFlag;
2014-09-29 14:38:52 -07:00
};
2014-10-03 18:27:06 -07:00
Transaction.fromHex = function(hex) {
return bitcoin.tx(bitcoindjs.txFromHex(hex));
};
2014-09-26 11:34:55 -07:00
Transaction.prototype.verify = function() {
2014-09-26 11:39:25 -07:00
return this.verified = this.verified || bitcoindjs.verifyTransaction(this);
2014-09-26 11:34:55 -07:00
};
Transaction.prototype.sign =
Transaction.prototype.fill = function(options) {
return Transaction.fill(this, options);
};
Transaction.sign =
Transaction.fill = function(tx, options) {
2014-09-29 14:38:52 -07:00
var isTx = bitcoin.tx.isTx(tx)
, newTx;
if (!isTx) {
tx = bitcoin.tx(tx);
}
try {
newTx = bitcoindjs.fillTransaction(tx, options || {});
2014-09-29 14:38:52 -07:00
} catch (e) {
return false;
}
Object.keys(newTx).forEach(function(key) {
tx[key] = newTx[key];
});
return isTx ? true : tx;
};
Transaction.prototype.getHash = function(enc) {
var data = bitcoindjs.getTxHex(this);
if (!this.txid || this.txid !== data.hash) {
this.txid = data.hash;
}
2014-10-03 16:39:26 -07:00
if (enc === 'hex') return data.hash;
var buf = new Buffer(data.hash, 'hex');
var out = enc ? buf.toString(enc) : buf;
return out;
};
2014-09-25 10:59:36 -07:00
Transaction.prototype.isCoinbase = function() {
return this.vin.length === 1 && this.vin[0].coinbase;
2014-09-25 10:59:36 -07:00
};
2014-09-25 12:05:39 -07:00
Transaction.prototype.toHex = function() {
var hex = Transaction.toHex(this);
if (!this.hex || hex !== this.hex) {
this.hex = hex;
}
return hex;
2014-09-25 12:05:39 -07:00
};
Transaction.toHex = function(tx) {
var data = bitcoindjs.getTxHex(tx);
return data.hex;
};
Transaction.prototype.toBinary = function() {
return Transaction.toBinary(this);
2014-09-25 12:05:39 -07:00
};
2014-09-25 13:17:07 -07:00
Transaction.toBinary = function(tx) {
var data = bitcoindjs.getTxHex(tx);
return new Buffer(data.hex, 'hex');
};
2014-09-25 13:39:06 -07:00
Transaction.broadcast = function(tx, options, callback) {
if (typeof tx === 'string') {
tx = { hex: tx };
}
if (!callback) {
callback = options;
options = null;
}
if (!options) {
options = {};
}
2014-09-25 13:58:54 -07:00
var fee = options.overrideFees = options.overrideFees || false;
var own = options.ownOnly = options.ownOnly || false;
if (!callback) {
2014-09-25 14:04:59 -07:00
callback = utils.NOOP;
2014-09-25 13:58:54 -07:00
}
2014-09-25 13:39:06 -07:00
if (!bitcoin.isTx(tx)) {
2014-09-25 13:39:06 -07:00
tx = bitcoin.tx(tx);
}
2014-09-25 14:01:50 -07:00
return bitcoindjs.broadcastTx(tx, fee, own, function(err, hash, tx) {
2014-09-25 14:04:59 -07:00
if (err) {
if (callback === utils.NOOP) {
bitcoin.global.emit('error', err);
}
return callback(err);
}
2014-09-25 14:01:50 -07:00
tx = bitcoin.tx(tx);
bitcoin.global.emit('broadcast', tx);
return callback(null, hash, tx);
2014-09-25 13:58:54 -07:00
});
2014-09-25 13:39:06 -07:00
};
2014-09-25 13:58:54 -07:00
Transaction.prototype.broadcast = function(options, callback) {
if (!callback) {
callback = options;
options = null;
}
return Transaction.broadcast(this, options, callback);
2014-09-25 13:39:06 -07:00
};
2014-09-26 12:20:00 -07:00
/**
* Wallet
* Singleton
2014-09-26 12:20:00 -07:00
*/
function Wallet() {
var obj = function() {
return obj;
};
Object.keys(Wallet.prototype).forEach(function(key) {
obj[key] = Wallet.prototype[key];
});
return obj;
}
2014-09-26 12:20:00 -07:00
2014-09-29 12:29:20 -07:00
Wallet.prototype.createAddress = function(options) {
return bitcoindjs.walletNewAddress(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.getAccountAddress = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletGetAccountAddress(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.setAccount = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletSetAccount(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.getAccount = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletGetAccount(options || {});
2014-09-26 12:20:00 -07:00
};
2014-09-29 12:26:46 -07:00
Wallet.prototype.sendTo = function(options) {
return bitcoindjs.walletSendTo(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.signMessage = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletSignMessage(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.verifyMessage = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletVerifyMessage(options || {});
2014-09-26 12:20:00 -07:00
};
2014-10-01 13:37:18 -07:00
Wallet.prototype.createMultiSigAddress = function(options) {
return bitcoindjs.walletCreateMultiSigAddress(options || {});
};
2014-09-26 12:20:00 -07:00
Wallet.prototype.getBalance = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletGetBalance(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.getUnconfirmedBalance = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletGetUnconfirmedBalance(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.sendFrom = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletSendFrom(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.listTransactions = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletListTransactions(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.listAccounts = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletListAccounts(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.getTransaction = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletGetTransaction(options || {});
2014-09-26 12:20:00 -07:00
};
2014-09-29 12:29:20 -07:00
Wallet.prototype.backup = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletBackup(options || {});
2014-09-26 12:20:00 -07:00
};
2014-09-29 12:29:20 -07:00
Wallet.prototype.decrypt =
Wallet.prototype.passphrase = function(options) {
return bitcoindjs.walletPassphrase(options || {});
2014-09-26 12:20:00 -07:00
};
2014-09-29 12:29:20 -07:00
Wallet.prototype.passphraseChange = function(options) {
return bitcoindjs.walletPassphraseChange(options || {});
2014-09-26 12:20:00 -07:00
};
2014-09-29 12:29:20 -07:00
Wallet.prototype.forgetPassphrase =
Wallet.prototype.lock = function(options) {
return bitcoindjs.walletLock(options || {});
2014-09-26 12:20:00 -07:00
};
2014-09-29 12:29:20 -07:00
Wallet.prototype.encrypt = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletEncrypt(options || {});
2014-09-26 12:20:00 -07:00
};
Wallet.prototype.setTxFee = function(options) {
2014-09-29 12:26:46 -07:00
return bitcoindjs.walletSetTxFee(options || {});
2014-09-26 12:20:00 -07:00
};
2014-10-01 16:00:21 -07:00
Wallet.prototype.importKey = function(options) {
return bitcoindjs.walletImportKey(options || {});
};
2014-09-26 12:20:00 -07:00
Wallet = new Wallet;
2014-09-22 12:14:51 -07:00
/**
* Utils
*/
var utils = {};
2014-09-22 18:21:08 -07:00
utils.forEach = function(obj, iter, done) {
var pending = obj.length;
if (!pending) return done();
var next = function() {
if (!--pending) done();
};
obj.forEach(function(item) {
iter(item, next);
});
};
2014-09-25 14:04:59 -07:00
utils.NOOP = function() {};
2014-08-12 12:03:04 -07:00
/**
* Expose
*/
2014-09-25 13:39:06 -07:00
module.exports = exports = bitcoin;
exports.Bitcoin = bitcoin;
exports.bitcoin = bitcoin;
exports.bitcoind = bitcoin;
2014-08-12 12:03:04 -07:00
exports.native = bitcoindjs;
2014-09-25 13:39:06 -07:00
exports.bitcoindjs = bitcoindjs;
exports.Block = Block;
exports.block = Block;
exports.Transaction = Transaction;
exports.transaction = Transaction;
exports.tx = Transaction;
exports.Wallet = Wallet;
exports.wallet = Wallet;
2014-09-22 12:14:51 -07:00
exports.utils = utils;