misc. error handling.
This commit is contained in:
parent
f4b0d029df
commit
5b3cc7c0d3
@ -755,7 +755,7 @@ TXDB.prototype._confirm = function _confirm(tx, map, callback, force) {
|
|||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
self.emit('confirmed');
|
self.emit('confirmed', tx, map);
|
||||||
self.emit('tx', tx, map);
|
self.emit('tx', tx, map);
|
||||||
|
|
||||||
return callback(null, true);
|
return callback(null, true);
|
||||||
|
|||||||
@ -497,6 +497,9 @@ Wallet.prototype.fill = function fill(tx, options, callback) {
|
|||||||
account = self.account;
|
account = self.account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!account.initialized)
|
||||||
|
return callback(new Error('Account is not initialized.'));
|
||||||
|
|
||||||
self.getCoins(options.account, function(err, coins) {
|
self.getCoins(options.account, function(err, coins) {
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -689,34 +692,25 @@ Wallet.prototype.getPath = function getPath(address, callback) {
|
|||||||
Wallet.prototype.getInputPaths = function getInputPaths(tx, callback) {
|
Wallet.prototype.getInputPaths = function getInputPaths(tx, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var paths = [];
|
var paths = [];
|
||||||
|
var hashes;
|
||||||
|
|
||||||
if (tx instanceof bcoin.input) {
|
if (tx instanceof bcoin.input) {
|
||||||
if (!tx.coin)
|
if (!tx.coin)
|
||||||
return callback(new Error('Not all coins available.'));
|
return callback(new Error('Not all coins available.'));
|
||||||
|
hashes = [tx.coin.getHash()];
|
||||||
return this.getPath(tx.coin.getHash(), function(err, path) {
|
} else {
|
||||||
if (err)
|
if (!tx.hasCoins())
|
||||||
return callback(err);
|
return callback(new Error('Not all coins available.'));
|
||||||
|
hashes = tx.getInputHashes();
|
||||||
if (path)
|
|
||||||
paths.push(path);
|
|
||||||
|
|
||||||
return callback(null, paths);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tx.hasCoins())
|
utils.forEachSerial(hashes, function(hash, next, i) {
|
||||||
return next(new Error('Not all coins available.'));
|
|
||||||
|
|
||||||
utils.forEachSerial(tx.getInputHashes(), function(hash, next, i) {
|
|
||||||
self.getPath(hash, function(err, path) {
|
self.getPath(hash, function(err, path) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
if (!path)
|
if (path)
|
||||||
return next();
|
paths.push(path);
|
||||||
|
|
||||||
paths.push(path);
|
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
@ -736,26 +730,20 @@ Wallet.prototype.getInputPaths = function getInputPaths(tx, callback) {
|
|||||||
Wallet.prototype.getOutputPaths = function getOutputPaths(tx, callback) {
|
Wallet.prototype.getOutputPaths = function getOutputPaths(tx, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var paths = [];
|
var paths = [];
|
||||||
|
var hashes;
|
||||||
|
|
||||||
if (tx instanceof bcoin.output) {
|
if (tx instanceof bcoin.output)
|
||||||
return this.getPath(tx.getHash(), function(err, path) {
|
hashes = [tx.getHash()];
|
||||||
if (err)
|
else
|
||||||
return callback(err);
|
hashes = tx.getOutputHashes();
|
||||||
if (path)
|
|
||||||
paths.push(path);
|
|
||||||
return callback(null, paths);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.forEachSerial(tx.getOutputHashes(), function(hash, next, i) {
|
utils.forEachSerial(hashes, function(hash, next, i) {
|
||||||
self.getPath(hash, function(err, path) {
|
self.getPath(hash, function(err, path) {
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return next(err);
|
||||||
|
|
||||||
if (!path)
|
if (path)
|
||||||
return next();
|
paths.push(path);
|
||||||
|
|
||||||
paths.push(path);
|
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
@ -1183,6 +1171,8 @@ Wallet.prototype.getTimeRange = function getTimeRange(account, options, callback
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getPublicKey = function getPublicKey(enc) {
|
Wallet.prototype.getPublicKey = function getPublicKey(enc) {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getPublicKey(enc);
|
return this.receiveAddress.getPublicKey(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1192,6 +1182,8 @@ Wallet.prototype.getPublicKey = function getPublicKey(enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getScript = function getScript() {
|
Wallet.prototype.getScript = function getScript() {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getScript();
|
return this.receiveAddress.getScript();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1202,6 +1194,8 @@ Wallet.prototype.getScript = function getScript() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getScriptHash = function getScriptHash(enc) {
|
Wallet.prototype.getScriptHash = function getScriptHash(enc) {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getScriptHash(enc);
|
return this.receiveAddress.getScriptHash(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1212,6 +1206,8 @@ Wallet.prototype.getScriptHash = function getScriptHash(enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getScriptHash160 = function getScriptHash160(enc) {
|
Wallet.prototype.getScriptHash160 = function getScriptHash160(enc) {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getScriptHash160(enc);
|
return this.receiveAddress.getScriptHash160(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1222,6 +1218,8 @@ Wallet.prototype.getScriptHash160 = function getScriptHash160(enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getScriptHash256 = function getScriptHash256(enc) {
|
Wallet.prototype.getScriptHash256 = function getScriptHash256(enc) {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getScriptHash256(enc);
|
return this.receiveAddress.getScriptHash256(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1231,6 +1229,8 @@ Wallet.prototype.getScriptHash256 = function getScriptHash256(enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getScriptAddress = function getScriptAddress() {
|
Wallet.prototype.getScriptAddress = function getScriptAddress() {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getScriptAddress();
|
return this.receiveAddress.getScriptAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1240,6 +1240,8 @@ Wallet.prototype.getScriptAddress = function getScriptAddress() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getProgram = function getProgram() {
|
Wallet.prototype.getProgram = function getProgram() {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getProgram();
|
return this.receiveAddress.getProgram();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1251,6 +1253,8 @@ Wallet.prototype.getProgram = function getProgram() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getProgramHash = function getProgramHash(enc) {
|
Wallet.prototype.getProgramHash = function getProgramHash(enc) {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getProgramHash(enc);
|
return this.receiveAddress.getProgramHash(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1261,6 +1265,8 @@ Wallet.prototype.getProgramHash = function getProgramHash(enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getProgramAddress = function getProgramAddress() {
|
Wallet.prototype.getProgramAddress = function getProgramAddress() {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getProgramAddress();
|
return this.receiveAddress.getProgramAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1271,6 +1277,8 @@ Wallet.prototype.getProgramAddress = function getProgramAddress() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getKeyHash = function getKeyHash(enc) {
|
Wallet.prototype.getKeyHash = function getKeyHash(enc) {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getKeyHash(enc);
|
return this.receiveAddress.getKeyHash(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1280,6 +1288,8 @@ Wallet.prototype.getKeyHash = function getKeyHash(enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getKeyAddress = function getKeyAddress() {
|
Wallet.prototype.getKeyAddress = function getKeyAddress() {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getKeyAddress();
|
return this.receiveAddress.getKeyAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1290,6 +1300,8 @@ Wallet.prototype.getKeyAddress = function getKeyAddress() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getHash = function getHash(enc) {
|
Wallet.prototype.getHash = function getHash(enc) {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getHash(enc);
|
return this.receiveAddress.getHash(enc);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1299,6 +1311,8 @@ Wallet.prototype.getHash = function getHash(enc) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Wallet.prototype.getAddress = function getAddress() {
|
Wallet.prototype.getAddress = function getAddress() {
|
||||||
|
if (!this.receiveAddress)
|
||||||
|
return;
|
||||||
return this.receiveAddress.getAddress();
|
return this.receiveAddress.getAddress();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1355,22 +1369,32 @@ Wallet.prototype.__defineGetter__('address', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Wallet.prototype.__defineGetter__('receiveDepth', function() {
|
Wallet.prototype.__defineGetter__('receiveDepth', function() {
|
||||||
|
if (!this.account)
|
||||||
|
return -1;
|
||||||
return this.account.receiveDepth;
|
return this.account.receiveDepth;
|
||||||
});
|
});
|
||||||
|
|
||||||
Wallet.prototype.__defineGetter__('changeDepth', function() {
|
Wallet.prototype.__defineGetter__('changeDepth', function() {
|
||||||
|
if (!this.account)
|
||||||
|
return -1;
|
||||||
return this.account.changeDepth;
|
return this.account.changeDepth;
|
||||||
});
|
});
|
||||||
|
|
||||||
Wallet.prototype.__defineGetter__('accountKey', function() {
|
Wallet.prototype.__defineGetter__('accountKey', function() {
|
||||||
|
if (!this.account)
|
||||||
|
return;
|
||||||
return this.account.accountKey;
|
return this.account.accountKey;
|
||||||
});
|
});
|
||||||
|
|
||||||
Wallet.prototype.__defineGetter__('receiveAddress', function() {
|
Wallet.prototype.__defineGetter__('receiveAddress', function() {
|
||||||
|
if (!this.account)
|
||||||
|
return;
|
||||||
return this.account.receiveAddress;
|
return this.account.receiveAddress;
|
||||||
});
|
});
|
||||||
|
|
||||||
Wallet.prototype.__defineGetter__('changeAddress', function() {
|
Wallet.prototype.__defineGetter__('changeAddress', function() {
|
||||||
|
if (!this.account)
|
||||||
|
return;
|
||||||
return this.account.changeAddress;
|
return this.account.changeAddress;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1578,9 +1602,6 @@ function Account(options) {
|
|||||||
if (!this.name)
|
if (!this.name)
|
||||||
this.name = this.accountIndex + '';
|
this.name = this.accountIndex + '';
|
||||||
|
|
||||||
// Non-alphanumeric IDs will break leveldb sorting.
|
|
||||||
assert(/^[a-zA-Z0-9]+$/.test(this.name), 'Account IDs must be alphanumeric.');
|
|
||||||
|
|
||||||
this.pushKey(this.accountKey);
|
this.pushKey(this.accountKey);
|
||||||
|
|
||||||
if (options.keys) {
|
if (options.keys) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user