major refactor.

This commit is contained in:
Christopher Jeffrey 2016-04-16 06:59:32 -07:00
parent 0d7d8073a2
commit 0f6c19bcd5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
18 changed files with 261 additions and 260 deletions

View File

@ -154,9 +154,9 @@ function getCoin(callback) {
});
}
function getWalletAll(callback) {
function getWalletHistory(callback) {
var id = getID();
client.getWalletAll(id, function(err, txs) {
client.getWalletHistory(id, function(err, txs) {
if (err)
return callback(err);
utils.print(txs);
@ -228,7 +228,7 @@ function main(callback) {
case 'balance':
return getBalance(callback);
case 'history':
return getWalletAll(callback);
return getWalletHistory(callback);
case 'send':
return send(callback);
case 'zap':

View File

@ -982,12 +982,12 @@ ChainDB.prototype.fillCoins = function fillCoins(tx, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
ChainDB.prototype.fillTX = function fillTX(tx, callback) {
ChainDB.prototype.fillHistory = function fillHistory(tx, callback) {
var self = this;
if (Array.isArray(tx)) {
return utils.forEachSerial(tx, function(tx, next) {
self.fillTX(tx, next);
self.fillHistory(tx, next);
}, function(err) {
if (err)
return callback(err);
@ -1282,7 +1282,7 @@ ChainDB.prototype.getFullTX = function getFullTX(hash, callback) {
if (!tx)
return callback();
return self.fillTX(tx, function(err) {
return self.fillHistory(tx, function(err) {
if (err)
return callback(err);
@ -1307,7 +1307,7 @@ ChainDB.prototype.getFullBlock = function getFullBlock(hash, callback) {
if (!block)
return callback();
return self.fillTX(block.txs, function(err) {
return self.fillHistory(block.txs, function(err) {
if (err)
return callback(err);
@ -1346,7 +1346,7 @@ ChainDB.prototype._ensureHistory = function _ensureHistory(hash, callback) {
if (!block)
return callback();
return self.fillTXBlock(block, callback);
return self.fillHistoryBlock(block, callback);
});
};
@ -1392,8 +1392,8 @@ ChainDB.prototype.fillBlock = function fillBlock(block, callback) {
* @param {Function} callback - Returns [Error, {@link Block}].
*/
ChainDB.prototype.fillTXBlock = function fillTXBlock(block, callback) {
return this.fillTX(block.txs, function(err) {
ChainDB.prototype.fillHistoryBlock = function fillHistoryBlock(block, callback) {
return this.fillHistory(block.txs, function(err) {
var coins, i, tx, hash, j, input, key;
if (err)

View File

@ -34,14 +34,14 @@ ec.elliptic = elliptic.ec('secp256k1');
/**
* elliptic.js signature constructor.
* @constructor
* @static
*/
ec.signature = require('elliptic/lib/elliptic/ec/signature');
/**
* elliptic.js keypair constructor.
* @constructor
* @static
*/
ec.keypair = require('elliptic/lib/elliptic/ec/key');

View File

@ -94,11 +94,11 @@ try {
* @property {Function} miner - {@link Miner} constructor.
* @property {Function} minerblock - {@link MinerBlock} constructor.
* @property {Object} http
* @property {Function} http.client - {@link Client} constructor.
* @property {Function} http.http - {@link HTTPServer} constructor.
* @property {Function} http.client - {@link HTTPClient} constructor.
* @property {Function} http.http - {@link HTTPBase} constructor.
* @property {Function} http.provider - {@link HTTPProvider} constructor.
* @property {Function} http.request - See {@link request}.
* @property {Function} http.server - {@link NodeServer} constructor.
* @property {Function} http.server - {@link HTTPServer} constructor.
* @property {Object} workers - See {@link module:workers}.
*/
@ -200,6 +200,7 @@ function Environment(options) {
this.mtx = require('./mtx')(this);
this.mutabletransaction = this.mtx;
this.txdb = require('./txdb')(this);
this.transactiondb = this.txdb;
this.abstractblock = require('./abstractblock')(this);
this.compactblock = require('./compactblock')(this);
this.block = require('./block')(this);

View File

@ -37,7 +37,7 @@ var assert = utils.assert;
* @property {Pool} pool
* @property {Miner} miner
* @property {WalletDB} walletdb
* @property {NodeServer} http
* @property {HTTPServer} http
* @emits Fullnode#block
* @emits Fullnode#tx
* @emits Fullnode#error
@ -584,8 +584,8 @@ Fullnode.prototype.fillCoins = function fillCoins(tx, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Fullnode.prototype.fillTX = function fillTX(tx, callback) {
return this.mempool.fillAllTX(tx, callback);
Fullnode.prototype.fillHistory = function fillHistory(tx, callback) {
return this.mempool.fillAllHistory(tx, callback);
};
/**

View File

@ -15,15 +15,15 @@ var request = require('./request');
/**
* BCoin HTTP client.
* @exports Client
* @exports HTTPClient
* @constructor
* @param {String} uri
* @param {Object?} options
*/
function Client(uri, options) {
if (!(this instanceof Client))
return new Client(uri, options);
function HTTPClient(uri, options) {
if (!(this instanceof HTTPClient))
return new HTTPClient(uri, options);
if (!options)
options = {};
@ -37,9 +37,9 @@ function Client(uri, options) {
this._init();
}
utils.inherits(Client, EventEmitter);
utils.inherits(HTTPClient, EventEmitter);
Client.prototype._init = function _init() {
HTTPClient.prototype._init = function _init() {
var self = this;
var io;
@ -123,7 +123,7 @@ Client.prototype._init = function _init() {
* @param {Function} callback
*/
Client.prototype.open = function open(callback) {
HTTPClient.prototype.open = function open(callback) {
if (this.loaded)
return utils.nextTick(callback);
@ -135,7 +135,7 @@ Client.prototype.open = function open(callback) {
* @param {WalletID} id
*/
Client.prototype.listenWallet = function listenWallet(id) {
HTTPClient.prototype.listenWallet = function listenWallet(id) {
if (!this.socket)
return;
@ -147,7 +147,7 @@ Client.prototype.listenWallet = function listenWallet(id) {
* @param {WalletID} id
*/
Client.prototype.unlistenWallet = function unlistenWallet(id) {
HTTPClient.prototype.unlistenWallet = function unlistenWallet(id) {
if (!this.socket)
return;
@ -158,7 +158,7 @@ Client.prototype.unlistenWallet = function unlistenWallet(id) {
* Listen for events on all wallets.
*/
Client.prototype.listenAll = function listenAll() {
HTTPClient.prototype.listenAll = function listenAll() {
this.listenWallet('!all');
};
@ -166,7 +166,7 @@ Client.prototype.listenAll = function listenAll() {
* Unlisten for events on all wallets.
*/
Client.prototype.unlistenAll = function unlistenAll() {
HTTPClient.prototype.unlistenAll = function unlistenAll() {
this.unlistenWallet('!all');
};
@ -176,8 +176,8 @@ Client.prototype.unlistenAll = function unlistenAll() {
* @param {Function} callback
*/
Client.prototype.close =
Client.prototype.destroy = function destroy(callback) {
HTTPClient.prototype.close =
HTTPClient.prototype.destroy = function destroy(callback) {
callback = utils.ensure(callback);
if (!this.socket)
@ -198,7 +198,7 @@ Client.prototype.destroy = function destroy(callback) {
* @param {Function} callback - Returns [Error, Object?].
*/
Client.prototype._request = function _request(method, endpoint, json, callback) {
HTTPClient.prototype._request = function _request(method, endpoint, json, callback) {
var self = this;
var query;
var networkType;
@ -251,7 +251,7 @@ Client.prototype._request = function _request(method, endpoint, json, callback)
* @param {Function} callback - Returns [Error, Object?].
*/
Client.prototype._get = function _get(endpoint, json, callback) {
HTTPClient.prototype._get = function _get(endpoint, json, callback) {
return this._request('get', endpoint, json, callback);
};
@ -263,7 +263,7 @@ Client.prototype._get = function _get(endpoint, json, callback) {
* @param {Function} callback - Returns [Error, Object?].
*/
Client.prototype._post = function _post(endpoint, json, callback) {
HTTPClient.prototype._post = function _post(endpoint, json, callback) {
return this._request('post', endpoint, json, callback);
};
@ -275,7 +275,7 @@ Client.prototype._post = function _post(endpoint, json, callback) {
* @param {Function} callback - Returns [Error, Object?].
*/
Client.prototype._put = function _put(endpoint, json, callback) {
HTTPClient.prototype._put = function _put(endpoint, json, callback) {
return this._request('put', endpoint, json, callback);
};
@ -287,7 +287,7 @@ Client.prototype._put = function _put(endpoint, json, callback) {
* @param {Function} callback - Returns [Error, Object?].
*/
Client.prototype._del = function _del(endpoint, json, callback) {
HTTPClient.prototype._del = function _del(endpoint, json, callback) {
return this._request('delete', endpoint, json, callback);
};
@ -298,7 +298,7 @@ Client.prototype._del = function _del(endpoint, json, callback) {
* @param {Function} callback - Returns [Error, Object].
*/
Client.prototype._createWallet = function createWallet(options, callback) {
HTTPClient.prototype._createWallet = function createWallet(options, callback) {
return this._post('/wallet', options, callback);
};
@ -309,7 +309,7 @@ Client.prototype._createWallet = function createWallet(options, callback) {
* @param {Function} callback - Returns [Error, Object].
*/
Client.prototype._getWallet = function getWallet(id, callback) {
HTTPClient.prototype._getWallet = function getWallet(id, callback) {
return this._get('/wallet/' + id, callback);
};
@ -321,7 +321,7 @@ Client.prototype._getWallet = function getWallet(id, callback) {
* @param {Function} callback - Returns [Error, {@link Wallet}].
*/
Client.prototype.getWallet = function getWallet(id, passphrase, callback) {
HTTPClient.prototype.getWallet = function getWallet(id, passphrase, callback) {
var self = this;
var provider;
@ -349,7 +349,7 @@ Client.prototype.getWallet = function getWallet(id, passphrase, callback) {
* @param {Function} callback - Returns [Error, {@link Wallet}].
*/
Client.prototype.createWallet = function createWallet(options, callback) {
HTTPClient.prototype.createWallet = function createWallet(options, callback) {
var self = this;
return this._createWallet(options, function(err, json) {
if (err)
@ -373,8 +373,8 @@ Client.prototype.createWallet = function createWallet(options, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Client.prototype.getWalletAll = function getWalletAll(id, callback) {
return this._get('/wallet/' + id + '/tx/all', function(err, body) {
HTTPClient.prototype.getWalletHistory = function getWalletHistory(id, callback) {
return this._get('/wallet/' + id + '/tx/history', function(err, body) {
if (err)
return callback(err);
@ -399,7 +399,7 @@ Client.prototype.getWalletAll = function getWalletAll(id, callback) {
* @param {Function} callback - Returns [Error, {@link Coin}[]].
*/
Client.prototype.getWalletCoins = function getWalletCoins(id, callback) {
HTTPClient.prototype.getWalletCoins = function getWalletCoins(id, callback) {
return this._get('/wallet/' + id + '/coin', function(err, body) {
if (err)
return callback(err);
@ -425,8 +425,8 @@ Client.prototype.getWalletCoins = function getWalletCoins(id, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Client.prototype.getWalletPending = function getPending(id, callback) {
return this._get('/wallet/' + id + '/tx/pending', function(err, body) {
HTTPClient.prototype.getWalletUnconfirmed = function getUnconfirmed(id, callback) {
return this._get('/wallet/' + id + '/tx/unconfirmed', function(err, body) {
if (err)
return callback(err);
@ -451,7 +451,7 @@ Client.prototype.getWalletPending = function getPending(id, callback) {
* @param {Function} callback - Returns [Error, {@link Balance}].
*/
Client.prototype.getWalletBalance = function getBalance(id, callback) {
HTTPClient.prototype.getWalletBalance = function getBalance(id, callback) {
return this._get('/wallet/' + id + '/balance', function(err, body) {
if (err)
return callback(err);
@ -474,7 +474,7 @@ Client.prototype.getWalletBalance = function getBalance(id, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Client.prototype.getWalletLast = function getWalletLast(id, limit, callback) {
HTTPClient.prototype.getWalletLast = function getWalletLast(id, limit, callback) {
var options = { limit: limit };
return this._get('/wallet/' + id + '/tx/last', options, function(err, body) {
if (err)
@ -506,7 +506,7 @@ Client.prototype.getWalletLast = function getWalletLast(id, limit, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Client.prototype.getWalletRange = function getWalletRange(id, options, callback) {
HTTPClient.prototype.getWalletRange = function getWalletRange(id, options, callback) {
return this._get('/wallet/' + id + '/tx/range', options, function(err, body) {
if (err)
return callback(err);
@ -534,7 +534,7 @@ Client.prototype.getWalletRange = function getWalletRange(id, options, callback)
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Client.prototype.getWalletTX = function getTX(id, hash, callback) {
HTTPClient.prototype.getWalletTX = function getTX(id, hash, callback) {
hash = utils.revHex(hash);
return this._get('/wallet/' + id + '/tx/' + hash, function(err, body) {
@ -563,7 +563,7 @@ Client.prototype.getWalletTX = function getTX(id, hash, callback) {
* @param {Function} callback - Returns [Error, {@link Coin}[]].
*/
Client.prototype.getWalletCoin = function getCoin(id, hash, index, callback) {
HTTPClient.prototype.getWalletCoin = function getCoin(id, hash, index, callback) {
var path;
hash = utils.revHex(hash);
@ -595,7 +595,7 @@ Client.prototype.getWalletCoin = function getCoin(id, hash, index, callback) {
* @param {Function} callback
*/
Client.prototype.syncWallet = function syncWallet(id, options, callback) {
HTTPClient.prototype.syncWallet = function syncWallet(id, options, callback) {
var body = {
receiveDepth: options.receiveDepth,
changeDepth: options.changeDepth
@ -615,7 +615,7 @@ Client.prototype.syncWallet = function syncWallet(id, options, callback) {
* @param {Function} callback - Returns [Error, {@link Coin}[]].
*/
Client.prototype.getCoinsByAddress = function getCoinsByAddress(address, callback) {
HTTPClient.prototype.getCoinsByAddress = function getCoinsByAddress(address, callback) {
var body = { addresses: address };
return this._post('/coin/address', body, function(err, body) {
@ -645,7 +645,7 @@ Client.prototype.getCoinsByAddress = function getCoinsByAddress(address, callbac
* @param {Function} callback - Returns [Error, {@link Coin}].
*/
Client.prototype.getCoin = function getCoin(hash, index, callback) {
HTTPClient.prototype.getCoin = function getCoin(hash, index, callback) {
hash = utils.revHex(hash);
return this._get('/coin/' + hash + '/' + index, function(err, body) {
@ -672,7 +672,7 @@ Client.prototype.getCoin = function getCoin(hash, index, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Client.prototype.getTXByAddress = function getTXByAddress(address, callback) {
HTTPClient.prototype.getTXByAddress = function getTXByAddress(address, callback) {
var body = { addresses: address };
return this._post('/tx/address', body, function(err, body) {
@ -700,7 +700,7 @@ Client.prototype.getTXByAddress = function getTXByAddress(address, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Client.prototype.getTX = function getTX(hash, callback) {
HTTPClient.prototype.getTX = function getTX(hash, callback) {
hash = utils.revHex(hash);
return this._get('/tx/' + hash, function(err, body) {
@ -726,7 +726,7 @@ Client.prototype.getTX = function getTX(hash, callback) {
* @param {Function} callback - Returns [Error, {@link Block}].
*/
Client.prototype.getBlock = function getBlock(hash, callback) {
HTTPClient.prototype.getBlock = function getBlock(hash, callback) {
if (typeof hash !== 'number')
hash = utils.revHex(hash);
@ -753,7 +753,7 @@ Client.prototype.getBlock = function getBlock(hash, callback) {
* @param {Function} callback
*/
Client.prototype.broadcast = function broadcast(tx, callback) {
HTTPClient.prototype.broadcast = function broadcast(tx, callback) {
var body = { tx: utils.toHex(tx.toRaw()) };
callback = utils.ensure(callback);
@ -774,7 +774,7 @@ Client.prototype.broadcast = function broadcast(tx, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Client.prototype.walletSend = function walletSend(id, options, callback) {
HTTPClient.prototype.walletSend = function walletSend(id, options, callback) {
var body = {
address: options.address,
value: utils.btc(options.value)
@ -803,7 +803,7 @@ Client.prototype.walletSend = function walletSend(id, options, callback) {
* @param {Function} callback
*/
Client.prototype.zapWallet = function zapWallet(id, now, age, callback) {
HTTPClient.prototype.zapWallet = function zapWallet(id, now, age, callback) {
var body = {
now: now,
age: age
@ -830,7 +830,7 @@ Client.prototype.zapWallet = function zapWallet(id, now, age, callback) {
* @param {Function} callback
*/
Client.prototype.addKey = function addKey(id, keys, callback) {
HTTPClient.prototype.addKey = function addKey(id, keys, callback) {
if (!Array.isArray(keys))
keys = [keys];
@ -855,7 +855,7 @@ Client.prototype.addKey = function addKey(id, keys, callback) {
* @param {Function} callback
*/
Client.prototype.removeKey = function removeKey(id, keys, callback) {
HTTPClient.prototype.removeKey = function removeKey(id, keys, callback) {
if (!Array.isArray(keys))
keys = [keys];
@ -877,7 +877,7 @@ Client.prototype.removeKey = function removeKey(id, keys, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Client.prototype.getMempool = function getMempool(callback) {
HTTPClient.prototype.getMempool = function getMempool(callback) {
return this._get('/mempool', function(err, body) {
if (err)
return callback(err);
@ -902,7 +902,7 @@ Client.prototype.getMempool = function getMempool(callback) {
* @param {Function} callback - Returns [Error, Object].
*/
Client.prototype.getInfo = function getInfo(callback) {
HTTPClient.prototype.getInfo = function getInfo(callback) {
return this._get('/', function(err, body) {
if (err)
return callback(err);
@ -914,5 +914,5 @@ Client.prototype.getInfo = function getInfo(callback) {
});
};
return Client;
return HTTPClient;
};

View File

@ -9,16 +9,16 @@ var EventEmitter = require('events').EventEmitter;
var utils = require('../utils');
/**
* HTTPServer
* @exports HTTPServer
* HTTPBase
* @exports HTTPBase
* @constructor
* @param {Object?} options
* @emits HTTPServer#websocket
* @emits HTTPBase#websocket
*/
function HTTPServer(options) {
if (!(this instanceof HTTPServer))
return new HTTPServer(options);
function HTTPBase(options) {
if (!(this instanceof HTTPBase))
return new HTTPBase(options);
if (!options)
options = {};
@ -42,9 +42,9 @@ function HTTPServer(options) {
this._init();
}
utils.inherits(HTTPServer, EventEmitter);
utils.inherits(HTTPBase, EventEmitter);
HTTPServer.prototype._init = function _init() {
HTTPBase.prototype._init = function _init() {
var self = this;
this._initRouter();
@ -67,7 +67,7 @@ HTTPServer.prototype._init = function _init() {
});
};
HTTPServer.prototype._initIO = function _initIO() {
HTTPBase.prototype._initIO = function _initIO() {
var self = this;
var io;
@ -90,7 +90,7 @@ HTTPServer.prototype._initIO = function _initIO() {
});
};
HTTPServer.prototype._initRouter = function _initRouter() {
HTTPBase.prototype._initRouter = function _initRouter() {
var self = this;
this.server.on('request', function(req, res) {
@ -181,7 +181,7 @@ HTTPServer.prototype._initRouter = function _initRouter() {
});
};
HTTPServer.prototype._handle = function _handle(req, res, _send, callback) {
HTTPBase.prototype._handle = function _handle(req, res, _send, callback) {
var self = this;
var i = 0;
var handler;
@ -223,7 +223,7 @@ HTTPServer.prototype._handle = function _handle(req, res, _send, callback) {
* @param {RouteCallback} callback
*/
HTTPServer.prototype.use = function use(path, callback) {
HTTPBase.prototype.use = function use(path, callback) {
if (!callback) {
callback = path;
path = null;
@ -245,7 +245,7 @@ HTTPServer.prototype.use = function use(path, callback) {
* @param {RouteCallback} callback
*/
HTTPServer.prototype.get = function get(path, callback) {
HTTPBase.prototype.get = function get(path, callback) {
if (Array.isArray(path)) {
path.forEach(function(path) {
this.get(path, callback);
@ -261,7 +261,7 @@ HTTPServer.prototype.get = function get(path, callback) {
* @param {RouteCallback} callback
*/
HTTPServer.prototype.post = function post(path, callback) {
HTTPBase.prototype.post = function post(path, callback) {
if (Array.isArray(path)) {
path.forEach(function(path) {
this.post(path, callback);
@ -277,7 +277,7 @@ HTTPServer.prototype.post = function post(path, callback) {
* @param {RouteCallback} callback
*/
HTTPServer.prototype.put = function put(path, callback) {
HTTPBase.prototype.put = function put(path, callback) {
if (Array.isArray(path)) {
path.forEach(function(path) {
this.put(path, callback);
@ -293,7 +293,7 @@ HTTPServer.prototype.put = function put(path, callback) {
* @param {RouteCallback} callback
*/
HTTPServer.prototype.del = function del(path, callback) {
HTTPBase.prototype.del = function del(path, callback) {
if (Array.isArray(path)) {
path.forEach(function(path) {
this.del(path, callback);
@ -308,7 +308,7 @@ HTTPServer.prototype.del = function del(path, callback) {
* @returns {Object}
*/
HTTPServer.prototype.address = function address() {
HTTPBase.prototype.address = function address() {
return this.server.address();
};
@ -319,7 +319,7 @@ HTTPServer.prototype.address = function address() {
* @param {Function} callback
*/
HTTPServer.prototype.listen = function listen(port, host, callback) {
HTTPBase.prototype.listen = function listen(port, host, callback) {
var self = this;
this.server.listen(port, host, function(err) {
if (!callback) {
@ -340,7 +340,7 @@ HTTPServer.prototype.listen = function listen(port, host, callback) {
* @param {Function} callback
*/
HTTPServer.prototype.close = function close(callback) {
HTTPBase.prototype.close = function close(callback) {
this.server.close(callback);
};
@ -506,4 +506,4 @@ function unescape(str) {
}
}
module.exports = HTTPServer;
module.exports = HTTPBase;

View File

@ -13,7 +13,7 @@ module.exports = function(bcoin) {
bcoin.http.provider = require('./provider')(bcoin);
if (!bcoin.isBrowser) {
bcoin.http.http = require('./ht' + 'tp');
bcoin.http.base = require('./ht' + 'tp');
bcoin.http.server = require('./ser' + 'ver')(bcoin);
}

View File

@ -11,30 +11,30 @@ var EventEmitter = require('events').EventEmitter;
var utils = require('../utils');
var assert = utils.assert;
var Client = bcoin.http.client;
var HTTPClient = bcoin.http.client;
/**
* Provider
* HTTPProvider
* @exports HTTPProvider
* @constructor
* @param {String} uri
*/
function Provider(uri) {
if (!(this instanceof Provider))
return new Provider(uri);
function HTTPProvider(uri) {
if (!(this instanceof HTTPProvider))
return new HTTPProvider(uri);
EventEmitter.call(this);
this.client = new Client(uri);
this.client = new HTTPClient(uri);
this.uri = uri;
this.id = null;
this._init();
}
utils.inherits(Provider, EventEmitter);
utils.inherits(HTTPProvider, EventEmitter);
Provider.prototype._init = function _init() {
HTTPProvider.prototype._init = function _init() {
var self = this;
this.client.on('tx', function(tx) {
@ -59,29 +59,29 @@ Provider.prototype._init = function _init() {
};
/**
* @see Provider#setID
* @see HTTPProvider#setID
*/
Provider.prototype.setID = function setID(id) {
HTTPProvider.prototype.setID = function setID(id) {
assert(!this.id, 'ID has already been set.');
this.id = id;
this.client.listenWallet(id);
};
/**
* @see Provider#open
* @see HTTPProvider#open
*/
Provider.prototype.open = function open(callback) {
HTTPProvider.prototype.open = function open(callback) {
this.client.open(callback);
};
/**
* @see Provider#close
* @see HTTPProvider#close
*/
Provider.prototype.close =
Provider.prototype.destroy = function destroy(callback) {
HTTPProvider.prototype.close =
HTTPProvider.prototype.destroy = function destroy(callback) {
callback = utils.ensure(callback);
if (!this.client)
@ -92,90 +92,90 @@ Provider.prototype.destroy = function destroy(callback) {
};
/**
* @see Provider#getAll
* @see HTTPProvider#getHistory
*/
Provider.prototype.getAll = function getAll(callback) {
return this.client.getWalletAll(this.id, callback);
HTTPProvider.prototype.getHistory = function getHistory(callback) {
return this.client.getWalletHistory(this.id, callback);
};
/**
* @see Provider#getCoins
* @see HTTPProvider#getCoins
*/
Provider.prototype.getCoins = function getCoins(callback) {
HTTPProvider.prototype.getCoins = function getCoins(callback) {
return this.client.getWalletCoins(this.id, callback);
};
/**
* @see Provider#getPending
* @see HTTPProvider#getUnconfirmed
*/
Provider.prototype.getPending = function getPending(callback) {
return this.client.getWalletPending(this.id, callback);
HTTPProvider.prototype.getUnconfirmed = function getUnconfirmed(callback) {
return this.client.getWalletUnconfirmed(this.id, callback);
};
/**
* @see Provider#getBalance
* @see HTTPProvider#getBalance
*/
Provider.prototype.getBalance = function getBalance(callback) {
HTTPProvider.prototype.getBalance = function getBalance(callback) {
return this.client.getWalletBalance(this.id, callback);
};
/**
* @see Provider#getLastTime
* @see HTTPProvider#getLastTime
*/
Provider.prototype.getLastTime = function getLastTime(callback) {
HTTPProvider.prototype.getLastTime = function getLastTime(callback) {
assert(false);
};
/**
* @see Provider#getLast
* @see HTTPProvider#getLast
*/
Provider.prototype.getLast = function getLast(limit, callback) {
HTTPProvider.prototype.getLast = function getLast(limit, callback) {
return this.client.getWalletLast(this.id, limit, callback);
};
/**
* @see Provider#getRange
* @see HTTPProvider#getRange
*/
Provider.prototype.getRange = function getRange(options, callback) {
HTTPProvider.prototype.getRange = function getRange(options, callback) {
return this.client.getWalletRange(this.id, options, callback);
};
/**
* @see Provider#getTX
* @see HTTPProvider#getTX
*/
Provider.prototype.getTX = function getTX(hash, callback) {
HTTPProvider.prototype.getTX = function getTX(hash, callback) {
return this.client.getWalletTX(this.id, hash, callback);
};
/**
* @see Provider#getCoin
* @see HTTPProvider#getCoin
*/
Provider.prototype.getCoin = function getCoin(hash, index, callback) {
HTTPProvider.prototype.getCoin = function getCoin(hash, index, callback) {
return this.client.getWalletCoin(this.id, hash, index, callback);
};
/**
* @see Provider#fillTX
* @see HTTPProvider#fillHistory
*/
Provider.prototype.fillTX = function fillTX(tx, callback) {
HTTPProvider.prototype.fillHistory = function fillHistory(tx, callback) {
assert(false);
};
/**
* @see Provider#fillCoins
* @see HTTPProvider#fillCoins
*/
Provider.prototype.fillCoins = function fillCoins(tx, callback) {
HTTPProvider.prototype.fillCoins = function fillCoins(tx, callback) {
assert(false);
};
@ -185,7 +185,7 @@ Provider.prototype.fillCoins = function fillCoins(tx, callback) {
* @param {Address?} address - Newly allocated address if available.
*/
Provider.prototype.sync = function sync(wallet, address) {
HTTPProvider.prototype.sync = function sync(wallet, address) {
var self = this;
return this.client.syncWallet(this.id, wallet, function(err) {
if (err)
@ -194,12 +194,12 @@ Provider.prototype.sync = function sync(wallet, address) {
};
/**
* @see Provider#zap
* @see HTTPProvider#zap
*/
Provider.prototype.zap = function zap(now, age, callback) {
HTTPProvider.prototype.zap = function zap(now, age, callback) {
return this.client.zapWallet(this.id, now, age, callback);
};
return Provider;
return HTTPProvider;
};

View File

@ -10,21 +10,21 @@ module.exports = function(bcoin) {
var EventEmitter = require('events').EventEmitter;
var constants = bcoin.protocol.constants;
var network = bcoin.protocol.network;
var HTTPServer = bcoin.http.http;
var HTTPBase = bcoin.http.base;
var utils = require('../utils');
var assert = utils.assert;
/**
* NodeServer
* @exports NodeServer
* HTTPServer
* @exports HTTPServer
* @constructor
* @param {Object} options
* @param {Fullnode} options.node
* @see HTTPServer
* @emits NodeServer#websocket
* @see HTTPBase
* @emits HTTPServer#websocket
*/
function NodeServer(options) {
function HTTPServer(options) {
if (!options)
options = {};
@ -38,15 +38,15 @@ function NodeServer(options) {
this.pool = this.node.pool;
this.loaded = false;
this.server = new HTTPServer(options);
this.server = new HTTPBase(options);
this.io = null;
this._init();
}
utils.inherits(NodeServer, EventEmitter);
utils.inherits(HTTPServer, EventEmitter);
NodeServer.prototype._init = function _init() {
HTTPServer.prototype._init = function _init() {
var self = this;
this.server.on('request', function(req, res) {
@ -455,8 +455,8 @@ NodeServer.prototype._init = function _init() {
});
// Wallet TXs
this.get('/wallet/:id/tx/all', function(req, res, next, send) {
self.walletdb.getAll(req.options.id, function(err, txs) {
this.get('/wallet/:id/tx/history', function(req, res, next, send) {
self.walletdb.getHistory(req.options.id, function(err, txs) {
if (err)
return next(err);
@ -470,8 +470,8 @@ NodeServer.prototype._init = function _init() {
});
// Wallet Pending TXs
this.get('/wallet/:id/tx/pending', function(req, res, next, send) {
self.walletdb.getPending(req.options.id, function(err, txs) {
this.get('/wallet/:id/tx/unconfirmed', function(req, res, next, send) {
self.walletdb.getUnconfirmed(req.options.id, function(err, txs) {
if (err)
return next(err);
@ -543,7 +543,7 @@ NodeServer.prototype._init = function _init() {
// Mempool snapshot
this.get('/mempool', function(req, res, next, send) {
self.node.mempool.getAll(function(err, txs) {
self.node.mempool.getHistory(function(err, txs) {
if (err)
return callback(err);
@ -571,7 +571,7 @@ NodeServer.prototype._init = function _init() {
* @param {Function} callback
*/
NodeServer.prototype.open = function open(callback) {
HTTPServer.prototype.open = function open(callback) {
if (this.loaded)
return utils.nextTick(callback);
@ -584,12 +584,12 @@ NodeServer.prototype.open = function open(callback) {
* @param {Function} callback
*/
NodeServer.prototype.close =
NodeServer.prototype.destroy = function destroy(callback) {
HTTPServer.prototype.close =
HTTPServer.prototype.destroy = function destroy(callback) {
this.server.close(callback);
};
NodeServer.prototype._initIO = function _initIO() {
HTTPServer.prototype._initIO = function _initIO() {
var self = this;
if (!this.server.io)
@ -656,50 +656,50 @@ NodeServer.prototype._initIO = function _initIO() {
};
/**
* @see HTTPServer#use
* @see HTTPBase#use
*/
NodeServer.prototype.use = function use(path, callback) {
HTTPServer.prototype.use = function use(path, callback) {
return this.server.use(path, callback);
};
/**
* @see HTTPServer#get
* @see HTTPBase#get
*/
NodeServer.prototype.get = function get(path, callback) {
HTTPServer.prototype.get = function get(path, callback) {
return this.server.get(path, callback);
};
/**
* @see HTTPServer#post
* @see HTTPBase#post
*/
NodeServer.prototype.post = function post(path, callback) {
HTTPServer.prototype.post = function post(path, callback) {
return this.server.post(path, callback);
};
/**
* @see HTTPServer#put
* @see HTTPBase#put
*/
NodeServer.prototype.put = function put(path, callback) {
HTTPServer.prototype.put = function put(path, callback) {
return this.server.put(path, callback);
};
/**
* @see HTTPServer#del
* @see HTTPBase#del
*/
NodeServer.prototype.del = function del(path, callback) {
HTTPServer.prototype.del = function del(path, callback) {
return this.server.del(path, callback);
};
/**
* @see HTTPServer#listen
* @see HTTPBase#listen
*/
NodeServer.prototype.listen = function listen(port, host, callback) {
HTTPServer.prototype.listen = function listen(port, host, callback) {
var self = this;
return this.server.listen(port, host, function(err, address) {
if (err) {
@ -719,5 +719,5 @@ NodeServer.prototype.listen = function listen(port, host, callback) {
});
};
return NodeServer;
return HTTPServer;
};

View File

@ -491,8 +491,8 @@ Mempool.prototype.getTXByAddress = function getTXByAddress(addresses, callback)
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Mempool.prototype.fillTX = function fillTX(tx, callback) {
return this.tx.fillTX(tx, callback);
Mempool.prototype.fillHistory = function fillHistory(tx, callback) {
return this.tx.fillHistory(tx, callback);
};
/**
@ -695,7 +695,7 @@ Mempool.prototype.addUnchecked = function addUnchecked(tx, callback) {
Mempool.prototype.removeUnchecked = function removeUnchecked(tx, callback) {
var self = this;
this.fillAllTX(tx, function(err, tx) {
this.fillAllHistory(tx, function(err, tx) {
if (err)
return callback(err);
@ -960,8 +960,8 @@ Mempool.prototype.getBalance = function getBalance(callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Mempool.prototype.getAll = function getAll(callback) {
return this.tx.getAll(callback);
Mempool.prototype.getHistory = function getHistory(callback) {
return this.tx.getHistory(callback);
};
/**
@ -1195,24 +1195,24 @@ Mempool.prototype.seenTX = function seenTX(tx, callback) {
/**
* Fill transaction with all unspent _and spent_
* coins. Similar to {@link Mempool#fillTX}
* coins. Similar to {@link Mempool#fillHistory}
* except that it will also fill with coins
* from the blockchain as well.
* @param {TX} tx
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Mempool.prototype.fillAllTX = function fillAllTX(tx, callback) {
Mempool.prototype.fillAllHistory = function fillAllHistory(tx, callback) {
var self = this;
this.fillTX(tx, function(err) {
this.fillHistory(tx, function(err) {
if (err)
return callback(err);
if (tx.hasCoins())
return callback(null, tx);
self.chain.db.fillTX(tx, callback);
self.chain.db.fillHistory(tx, callback);
});
};
@ -1277,7 +1277,7 @@ Mempool.prototype.fillAllCoins = function fillAllCoins(tx, callback) {
*/
Mempool.prototype.getSnapshot = function getSnapshot(callback) {
return this.tx.getAllHashes(callback);
return this.tx.getHistoryHashes(callback);
};
/**

View File

@ -1364,7 +1364,7 @@ Pool.prototype.addWallet = function addWallet(wallet, callback) {
if (this.options.spv)
this.watchWallet(wallet);
wallet.getPending(function(err, txs) {
wallet.getUnconfirmed(function(err, txs) {
if (err)
return callback(err);
@ -1990,7 +1990,7 @@ Pool.prototype.getUTXOs = function getUTXOs(utxos, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Pool.prototype.fillTX = function fillTX(tx, callback) {
Pool.prototype.fillHistory = function fillHistory(tx, callback) {
var utxos = [];
var reqs = [];
var i, input;

View File

@ -26,7 +26,7 @@ var assert = utils.assert;
* @property {Chain} chain
* @property {Pool} pool
* @property {WalletDB} walletdb
* @property {NodeServer} http
* @property {HTTPServer} http
* @emits SPVNode#block
* @emits SPVNode#tx
* @emits SPVNode#error

View File

@ -17,11 +17,11 @@ var BufferReader = require('./reader');
var BufferWriter = require('./writer');
/**
* TXPool
* TXDB
* @exports TXDB
* @constructor
* @param {String} prefix - The prefix for
* the database (`pool/` by default).
* the database (`txdb/` by default).
* @param {LowlevelUp} db
* @param {Object?} options
* @param {Boolean?} options.mapAddress - Map addresses to IDs.
@ -32,9 +32,9 @@ var BufferWriter = require('./writer');
* @property {String} prefix
*/
function TXPool(prefix, db, options) {
if (!(this instanceof TXPool))
return new TXPool(prefix, db, options);
function TXDB(prefix, db, options) {
if (!(this instanceof TXDB))
return new TXDB(prefix, db, options);
EventEmitter.call(this);
@ -42,7 +42,7 @@ function TXPool(prefix, db, options) {
options = {};
this.db = db;
this.prefix = prefix || 'pool';
this.prefix = prefix || 'txdb';
this.options = options;
this.busy = false;
this.jobs = [];
@ -52,9 +52,9 @@ function TXPool(prefix, db, options) {
this.options.indexAddress = true;
}
utils.inherits(TXPool, EventEmitter);
utils.inherits(TXDB, EventEmitter);
TXPool.prototype._lock = function _lock(func, args, force) {
TXDB.prototype._lock = function _lock(func, args, force) {
return this.locker.lock(func, args, force);
};
@ -85,7 +85,7 @@ TXPool.prototype._lock = function _lock(func, args, force) {
* @param {Function} callback - Returns [Error, {@link AddressMap}].
*/
TXPool.prototype.getMap = function getMap(tx, callback) {
TXDB.prototype.getMap = function getMap(tx, callback) {
var input, output, addresses, table, map;
if (!this.options.indexAddress)
@ -140,7 +140,7 @@ TXPool.prototype.getMap = function getMap(tx, callback) {
* @param {Function} callback - Returns [Error, {@link AddressTable}].
*/
TXPool.prototype.mapAddresses = function mapAddresses(address, callback) {
TXDB.prototype.mapAddresses = function mapAddresses(address, callback) {
var self = this;
var prefix = this.prefix + '/';
var table = {};
@ -212,7 +212,7 @@ TXPool.prototype.mapAddresses = function mapAddresses(address, callback) {
* @param {Function} callback - Returns [Error, Buffer].
*/
TXPool.prototype._addOrphan = function _addOrphan(key, hash, index, callback) {
TXDB.prototype._addOrphan = function _addOrphan(key, hash, index, callback) {
var prefix = this.prefix + '/';
var p;
@ -245,7 +245,7 @@ TXPool.prototype._addOrphan = function _addOrphan(key, hash, index, callback) {
* @param {Function} callback - Returns [Error, {@link Orphan}].
*/
TXPool.prototype._getOrphans = function _getOrphans(key, callback) {
TXDB.prototype._getOrphans = function _getOrphans(key, callback) {
var self = this;
var prefix = this.prefix + '/';
var p, orphans;
@ -297,7 +297,7 @@ TXPool.prototype._getOrphans = function _getOrphans(key, callback) {
* @param {Function} callback - Returns [Error].
*/
TXPool.prototype.add = function add(tx, callback, force) {
TXDB.prototype.add = function add(tx, callback, force) {
var self = this;
if (Array.isArray(tx)) {
@ -322,7 +322,7 @@ TXPool.prototype.add = function add(tx, callback, force) {
// This big scary function is what a persistent tx pool
// looks like. It's a semi mempool in that it can handle
// receiving txs out of order.
TXPool.prototype._add = function add(tx, map, callback, force) {
TXDB.prototype._add = function add(tx, map, callback, force) {
var self = this;
var prefix = this.prefix + '/';
var hash = tx.hash('hex');
@ -594,7 +594,7 @@ TXPool.prototype._add = function add(tx, map, callback, force) {
* @param {Function} callback - Returns [Error, Boolean].
*/
TXPool.prototype._removeSpenders = function removeSpenders(hash, ref, callback) {
TXDB.prototype._removeSpenders = function removeSpenders(hash, ref, callback) {
var self = this;
this.getTX(hash, function(err, tx) {
if (err)
@ -636,7 +636,7 @@ TXPool.prototype._removeSpenders = function removeSpenders(hash, ref, callback)
* @param {Function} callback - Returns [Error, Boolean].
*/
TXPool.prototype.isDoubleSpend = function isDoubleSpend(tx, callback) {
TXDB.prototype.isDoubleSpend = function isDoubleSpend(tx, callback) {
var self = this;
utils.everySerial(tx.inputs, function(input, next) {
self.isSpent(input.prevout.hash, input.prevout.index, function(err, spent) {
@ -661,7 +661,7 @@ TXPool.prototype.isDoubleSpend = function isDoubleSpend(tx, callback) {
* @param {Function} callback - Returns [Error, Boolean].
*/
TXPool.prototype.isSpent = function isSpent(hash, index, callback) {
TXDB.prototype.isSpent = function isSpent(hash, index, callback) {
var self = this;
var prefix = this.prefix + '/';
var key = prefix + 's/t/' + hash + '/' + index;
@ -687,7 +687,7 @@ TXPool.prototype.isSpent = function isSpent(hash, index, callback) {
* transaction was confirmed, or should be ignored.
*/
TXPool.prototype._confirm = function _confirm(tx, map, callback, force) {
TXDB.prototype._confirm = function _confirm(tx, map, callback, force) {
var self = this;
var prefix = this.prefix + '/';
var hash = tx.hash('hex');
@ -785,7 +785,7 @@ TXPool.prototype._confirm = function _confirm(tx, map, callback, force) {
* @param {Function} callback - Returns [Error].
*/
TXPool.prototype.remove = function remove(hash, callback, force) {
TXDB.prototype.remove = function remove(hash, callback, force) {
var self = this;
if (Array.isArray(hash)) {
@ -828,7 +828,7 @@ TXPool.prototype.remove = function remove(hash, callback, force) {
* @param {Function} callback - Returns [Error].
*/
TXPool.prototype.lazyRemove = function lazyRemove(tx, callback, force) {
TXDB.prototype.lazyRemove = function lazyRemove(tx, callback, force) {
var self = this;
if (Array.isArray(tx)) {
@ -858,7 +858,7 @@ TXPool.prototype.lazyRemove = function lazyRemove(tx, callback, force) {
* @param {Function} callback - Returns [Error].
*/
TXPool.prototype._remove = function remove(tx, map, callback, force) {
TXDB.prototype._remove = function remove(tx, map, callback, force) {
var self = this;
var prefix = this.prefix + '/';
var hash = tx.hash('hex');
@ -897,7 +897,7 @@ TXPool.prototype._remove = function remove(tx, map, callback, force) {
}
}
this.fillTX(tx, function(err) {
this.fillHistory(tx, function(err) {
if (err)
return callback(err);
@ -962,7 +962,7 @@ TXPool.prototype._remove = function remove(tx, map, callback, force) {
* @param {Function} callback
*/
TXPool.prototype.unconfirm = function unconfirm(hash, callback, force) {
TXDB.prototype.unconfirm = function unconfirm(hash, callback, force) {
var self = this;
if (Array.isArray(hash)) {
@ -1006,7 +1006,7 @@ TXPool.prototype.unconfirm = function unconfirm(hash, callback, force) {
* @param {Function} callback
*/
TXPool.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
TXDB.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
var self = this;
var prefix = this.prefix + '/';
var hash, batch, height, ts;
@ -1084,7 +1084,7 @@ TXPool.prototype._unconfirm = function unconfirm(tx, map, callback, force) {
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
TXPool.prototype.getAllHashes = function getAllHashes(address, callback) {
TXDB.prototype.getHistoryHashes = function getHistoryHashes(address, callback) {
var self = this;
var prefix = this.prefix + '/';
var txs = [];
@ -1099,7 +1099,7 @@ TXPool.prototype.getAllHashes = function getAllHashes(address, callback) {
if (Array.isArray(address)) {
return utils.forEachSerial(address, function(address, next) {
self.getAllHashes(address, function(err, tx) {
self.getHistoryHashes(address, function(err, tx) {
if (err)
return next(err);
@ -1158,7 +1158,7 @@ TXPool.prototype.getAllHashes = function getAllHashes(address, callback) {
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
TXPool.prototype.getPendingHashes = function getPendingHashes(address, callback) {
TXDB.prototype.getUnconfirmedHashes = function getUnconfirmedHashes(address, callback) {
var self = this;
var prefix = this.prefix + '/';
var txs = [];
@ -1174,7 +1174,7 @@ TXPool.prototype.getPendingHashes = function getPendingHashes(address, callback)
if (Array.isArray(address)) {
return utils.forEachSerial(address, function(address, next) {
assert(address);
self.getPendingHashes(address, function(err, tx) {
self.getUnconfirmedHashes(address, function(err, tx) {
if (err)
return next(err);
@ -1233,7 +1233,7 @@ TXPool.prototype.getPendingHashes = function getPendingHashes(address, callback)
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
TXPool.prototype.getCoinHashes = function getCoinHashes(address, callback) {
TXDB.prototype.getCoinHashes = function getCoinHashes(address, callback) {
var self = this;
var prefix = this.prefix + '/';
var coins = [];
@ -1316,7 +1316,7 @@ TXPool.prototype.getCoinHashes = function getCoinHashes(address, callback) {
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
TXPool.prototype.getHeightRangeHashes = function getHeightRangeHashes(address, options, callback) {
TXDB.prototype.getHeightRangeHashes = function getHeightRangeHashes(address, options, callback) {
var prefix = this.prefix + '/';
var txs = [];
var iter;
@ -1375,7 +1375,7 @@ TXPool.prototype.getHeightRangeHashes = function getHeightRangeHashes(address, o
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
TXPool.prototype.getHeightHashes = function getHeightHashes(height, callback) {
TXDB.prototype.getHeightHashes = function getHeightHashes(height, callback) {
return this.getHeightRangeHashes({ start: height, end: height }, callback);
};
@ -1390,7 +1390,7 @@ TXPool.prototype.getHeightHashes = function getHeightHashes(height, callback) {
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
TXPool.prototype.getRangeHashes = function getRangeHashes(address, options, callback) {
TXDB.prototype.getRangeHashes = function getRangeHashes(address, options, callback) {
var prefix = this.prefix + '/';
var txs = [];
var iter;
@ -1454,7 +1454,7 @@ TXPool.prototype.getRangeHashes = function getRangeHashes(address, options, call
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
TXPool.prototype.getRange = function getLast(address, options, callback) {
TXDB.prototype.getRange = function getLast(address, options, callback) {
var self = this;
var txs = [];
@ -1495,7 +1495,7 @@ TXPool.prototype.getRange = function getLast(address, options, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
TXPool.prototype.getLast = function getLast(address, limit, callback) {
TXDB.prototype.getLast = function getLast(address, limit, callback) {
if (typeof limit === 'function') {
callback = limit;
limit = address;
@ -1516,7 +1516,7 @@ TXPool.prototype.getLast = function getLast(address, limit, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
TXPool.prototype.getAll = function getAll(address, callback) {
TXDB.prototype.getHistory = function getHistory(address, callback) {
var self = this;
var txs = [];
@ -1525,7 +1525,7 @@ TXPool.prototype.getAll = function getAll(address, callback) {
address = null;
}
return this.getAllHashes(address, function(err, hashes) {
return this.getHistoryHashes(address, function(err, hashes) {
if (err)
return callback(err);
@ -1556,13 +1556,13 @@ TXPool.prototype.getAll = function getAll(address, callback) {
* @param {Function} callback - Returns [Error, Number(ts), Number(height)].
*/
TXPool.prototype.getLastTime = function getLastTime(address, callback) {
TXDB.prototype.getLastTime = function getLastTime(address, callback) {
if (typeof address === 'function') {
callback = address;
address = null;
}
return this.getAll(address, function(err, txs) {
return this.getHistory(address, function(err, txs) {
var lastTs, lastHeight;
if (err)
@ -1589,7 +1589,7 @@ TXPool.prototype.getLastTime = function getLastTime(address, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
TXPool.prototype.getPending = function getPending(address, callback) {
TXDB.prototype.getUnconfirmed = function getUnconfirmed(address, callback) {
var self = this;
var txs = [];
@ -1598,7 +1598,7 @@ TXPool.prototype.getPending = function getPending(address, callback) {
address = null;
}
return this.getPendingHashes(address, function(err, hashes) {
return this.getUnconfirmedHashes(address, function(err, hashes) {
if (err)
return callback(err);
@ -1629,7 +1629,7 @@ TXPool.prototype.getPending = function getPending(address, callback) {
* @param {Function} callback - Returns [Error, {@link Coin}[]].
*/
TXPool.prototype.getCoins = function getCoins(address, callback) {
TXDB.prototype.getCoins = function getCoins(address, callback) {
var self = this;
var coins = [];
@ -1669,12 +1669,12 @@ TXPool.prototype.getCoins = function getCoins(address, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
TXPool.prototype.fillTX = function fillTX(tx, callback) {
TXDB.prototype.fillHistory = function fillHistory(tx, callback) {
var self = this;
if (Array.isArray(tx)) {
return utils.forEachSerial(tx, function(tx, next) {
self.fillTX(tx, function(err) {
self.fillHistory(tx, function(err) {
if (err)
return next(err);
@ -1714,7 +1714,7 @@ TXPool.prototype.fillTX = function fillTX(tx, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
TXPool.prototype.fillCoins = function fillCoins(tx, callback) {
TXDB.prototype.fillCoins = function fillCoins(tx, callback) {
var self = this;
if (Array.isArray(tx)) {
@ -1759,7 +1759,7 @@ TXPool.prototype.fillCoins = function fillCoins(tx, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
TXPool.prototype.getTX = function getTX(hash, callback) {
TXDB.prototype.getTX = function getTX(hash, callback) {
var prefix = this.prefix + '/';
var key = prefix + 't/t/' + hash;
@ -1786,7 +1786,7 @@ TXPool.prototype.getTX = function getTX(hash, callback) {
* @param {Function} callback - Returns [Error, Boolean].
*/
TXPool.prototype.hasTX = function hasTX(hash, callback) {
TXDB.prototype.hasTX = function hasTX(hash, callback) {
return this.getTX(hash, function(err, tx) {
if (err)
return callback(err);
@ -1802,7 +1802,7 @@ TXPool.prototype.hasTX = function hasTX(hash, callback) {
* @param {Function} callback - Returns [Error, {@link Coin}].
*/
TXPool.prototype.getCoin = function getCoin(hash, index, callback) {
TXDB.prototype.getCoin = function getCoin(hash, index, callback) {
var prefix = this.prefix + '/';
var key = prefix + 'u/t/' + hash + '/' + index;
@ -1831,7 +1831,7 @@ TXPool.prototype.getCoin = function getCoin(hash, index, callback) {
* @param {Function} callback - Returns [Error, Boolean].
*/
TXPool.prototype.hasCoin = function hasCoin(hash, index, callback) {
TXDB.prototype.hasCoin = function hasCoin(hash, index, callback) {
return this.getCoin(hash, index, function(err, coin) {
if (err)
return callback(err);
@ -1846,7 +1846,7 @@ TXPool.prototype.hasCoin = function hasCoin(hash, index, callback) {
* @param {Function} callback - Returns [Error, {@link Balance}].
*/
TXPool.prototype.getBalance = function getBalance(address, callback) {
TXDB.prototype.getBalance = function getBalance(address, callback) {
var confirmed = new bn(0);
var unconfirmed = new bn(0);
var i;
@ -1881,8 +1881,8 @@ TXPool.prototype.getBalance = function getBalance(address, callback) {
* @param {Function} callback - Returns [Error, {@link Hash}[]].
*/
TXPool.prototype.getAllHashesByAddress = function getAllHashesByAddress(address, callback) {
return this.getAllHashes(address, callback);
TXDB.prototype.getHistoryHashesByAddress = function getHistoryHashesByAddress(address, callback) {
return this.getHistoryHashes(address, callback);
};
/**
@ -1891,8 +1891,8 @@ TXPool.prototype.getAllHashesByAddress = function getAllHashesByAddress(address,
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
TXPool.prototype.getAllByAddress = function getAllByAddress(address, callback) {
return this.getAll(address, callback);
TXDB.prototype.getHistoryByAddress = function getHistoryByAddress(address, callback) {
return this.getHistory(address, callback);
};
/**
@ -1901,7 +1901,7 @@ TXPool.prototype.getAllByAddress = function getAllByAddress(address, callback) {
* @param {Function} callback - Returns [Error, {@link Coin}[]].
*/
TXPool.prototype.getCoinsByAddress = function getCoins(address, callback) {
TXDB.prototype.getCoinsByAddress = function getCoins(address, callback) {
return this.getCoins(address, callback);
};
@ -1911,8 +1911,8 @@ TXPool.prototype.getCoinsByAddress = function getCoins(address, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
TXPool.prototype.getPendingByAddress = function getPendingByAddress(address, callback) {
return this.getPending(address, callback);
TXDB.prototype.getUnconfirmedByAddress = function getUnconfirmedByAddress(address, callback) {
return this.getUnconfirmed(address, callback);
};
/**
@ -1921,7 +1921,7 @@ TXPool.prototype.getPendingByAddress = function getPendingByAddress(address, cal
* @param {Function} callback - Returns [Error, {@link Balance}].
*/
TXPool.prototype.getBalanceByAddress = function getBalanceByAddress(address, callback) {
TXDB.prototype.getBalanceByAddress = function getBalanceByAddress(address, callback) {
return this.getBalance(address, callback);
};
@ -1932,7 +1932,7 @@ TXPool.prototype.getBalanceByAddress = function getBalanceByAddress(address, cal
* @param {Function} callback
*/
TXPool.prototype.zap = function zap(address, now, age, callback, force) {
TXDB.prototype.zap = function zap(address, now, age, callback, force) {
var self = this;
if (typeof address !== 'string') {
@ -1960,7 +1960,7 @@ TXPool.prototype.zap = function zap(address, now, age, callback, force) {
if (err)
return callback(err);
self.fillTX(txs, function(err) {
self.fillHistory(txs, function(err) {
if (err)
return callback(err);
@ -1973,5 +1973,5 @@ TXPool.prototype.zap = function zap(address, now, age, callback, force) {
});
};
return TXPool;
return TXDB;
};

View File

@ -766,7 +766,7 @@ Wallet.prototype.fillCoins = function fillCoins(tx, callback) {
if (!this.provider)
return callback(new Error('No wallet provider available.'));
return this.provider.fillTX(tx, callback);
return this.provider.fillHistory(tx, callback);
};
/**
@ -1073,17 +1073,17 @@ Wallet.prototype.zap = function zap(now, age, callback) {
/**
* Scan for addresses.
* @param {Function} txByAddress - Must be a callback which accepts
* @param {Function} getByAddress - Must be a callback which accepts
* a callback and returns transactions by address.
* @param {Function} callback - Returns [Boolean, TX[]].
*/
Wallet.prototype.scan = function scan(txByAddress, callback) {
Wallet.prototype.scan = function scan(getByAddress, callback) {
var self = this;
var res = false;
var i;
return this._scan({}, txByAddress, function(err, depth, txs) {
return this._scan({}, getByAddress, function(err, depth, txs) {
if (err)
return callback(err);
@ -1126,7 +1126,7 @@ Wallet.prototype.clone = function clone() {
return wallet;
};
Wallet.prototype._scan = function _scan(options, txByAddress, callback) {
Wallet.prototype._scan = function _scan(options, getByAddress, callback) {
var depth = { changeDepth: 0, receiveDepth: 0 };
var wallet = this.clone();
var all = [];
@ -1141,7 +1141,7 @@ Wallet.prototype._scan = function _scan(options, txByAddress, callback) {
(function next() {
var address = wallet.deriveAddress(change, addressIndex++);
txByAddress(address.getAddress(), function(err, txs) {
getByAddress(address.getAddress(), function(err, txs) {
var result;
if (err)
@ -1267,11 +1267,11 @@ Wallet.prototype.addTX = function addTX(tx, callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Wallet.prototype.getAll = function getAll(callback) {
Wallet.prototype.getHistory = function getHistory(callback) {
if (!this.provider)
return utils.asyncify(callback)(new Error('No wallet provider available.'));
return this.provider.getAll(callback);
return this.provider.getHistory(callback);
};
/**
@ -1291,11 +1291,11 @@ Wallet.prototype.getCoins = function getCoins(callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Wallet.prototype.getPending = function getPending(callback) {
Wallet.prototype.getUnconfirmed = function getUnconfirmed(callback) {
if (!this.provider)
return utils.asyncify(callback)(new Error('No wallet provider available.'));
return this.provider.getPending(callback);
return this.provider.getUnconfirmed(callback);
};
/**

View File

@ -749,12 +749,12 @@ WalletDB.prototype.getCoin = function getCoin(hash, index, callback) {
};
/**
* @see {@link TXDB#getAllByAddress}.
* @see {@link TXDB#getHistoryByAddress}.
*/
WalletDB.prototype.getAll = function getAll(id, callback) {
WalletDB.prototype.getHistory = function getHistory(id, callback) {
id = id.id || id;
return this.tx.getAllByAddress(id, callback);
return this.tx.getHistoryByAddress(id, callback);
};
/**
@ -767,12 +767,12 @@ WalletDB.prototype.getCoins = function getCoins(id, callback) {
};
/**
* @see {@link TXDB#getPendingByAddress}.
* @see {@link TXDB#getUnconfirmedByAddress}.
*/
WalletDB.prototype.getPending = function getPending(id, callback) {
WalletDB.prototype.getUnconfirmed = function getUnconfirmed(id, callback) {
id = id.id || id;
return this.tx.getPendingByAddress(id, callback);
return this.tx.getUnconfirmedByAddress(id, callback);
};
/**
@ -812,11 +812,11 @@ WalletDB.prototype.getRange = function getRange(id, options, callback) {
};
/**
* @see {@link TXDB#fillTX}.
* @see {@link TXDB#fillHistory}.
*/
WalletDB.prototype.fillTX = function fillTX(tx, callback) {
return this.tx.fillTX(tx, callback);
WalletDB.prototype.fillHistory = function fillHistory(tx, callback) {
return this.tx.fillHistory(tx, callback);
};
/**
@ -1027,8 +1027,8 @@ Provider.prototype.destroy = function destroy(callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Provider.prototype.getAll = function getAll(callback) {
return this.db.getAll(this.id, callback);
Provider.prototype.getHistory = function getHistory(callback) {
return this.db.getHistory(this.id, callback);
};
/**
@ -1045,8 +1045,8 @@ Provider.prototype.getCoins = function getCoins(callback) {
* @param {Function} callback - Returns [Error, {@link TX}[]].
*/
Provider.prototype.getPending = function getPending(callback) {
return this.db.getPending(this.id, callback);
Provider.prototype.getUnconfirmed = function getUnconfirmed(callback) {
return this.db.getUnconfirmed(this.id, callback);
};
/**
@ -1118,8 +1118,8 @@ Provider.prototype.getCoin = function getCoin(hash, index, callback) {
* @param {Function} callback - Returns [Error, {@link TX}].
*/
Provider.prototype.fillTX = function fillTX(tx, callback) {
return this.db.fillTX(tx, callback);
Provider.prototype.fillHistory = function fillHistory(tx, callback) {
return this.db.fillHistory(tx, callback);
};
/**

View File

@ -120,7 +120,7 @@ describe('Node', function() {
node.mempool.getBalance(function(err, balance) {
assert.noError(err);
assert.equal(balance.total.toString(10), '20000');
node.mempool.getAll(function(err, txs) {
node.mempool.getHistory(function(err, txs) {
assert(txs.some(function(tx) {
return tx.hash('hex') === f1.hash('hex');
}));

View File

@ -213,14 +213,14 @@ describe('Wallet', function() {
w.getBalance(function(err, balance) {
assert.noError(err);
assert.equal(balance.total.toString(10), '11000');
w.getAll(function(err, txs) {
w.getHistory(function(err, txs) {
assert(txs.some(function(tx) {
return tx.hash('hex') === f1.hash('hex');
}));
var w2 = bcoin.wallet.fromJSON(w.toJSON());
// assert.equal(w2.getBalance().toString(10), '11000');
// assert(w2.getAll().some(function(tx) {
// assert(w2.getHistory().some(function(tx) {
// return tx.hash('hex') === f1.hash('hex');
// }));
cb();