more path stuff.
This commit is contained in:
parent
f8fadb73a7
commit
0dc2b41f5e
@ -145,8 +145,8 @@ SPVNode.prototype._init = function _init() {
|
||||
});
|
||||
});
|
||||
|
||||
this.walletdb.on('save address', function(hash) {
|
||||
self.pool.watch(hash, 'hex');
|
||||
this.walletdb.on('save address', function(address) {
|
||||
self.pool.watch(address.getHash());
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -749,9 +749,9 @@ WalletDB.prototype.hasAccount = function hasAccount(id, account, callback) {
|
||||
|
||||
WalletDB.prototype.saveAddress = function saveAddress(id, addresses, callback) {
|
||||
var self = this;
|
||||
var hashes = [];
|
||||
var items = [];
|
||||
var batch = this.db.batch();
|
||||
var i, address;
|
||||
var i, address, path;
|
||||
|
||||
if (!Array.isArray(addresses))
|
||||
addresses = [addresses];
|
||||
@ -759,22 +759,31 @@ WalletDB.prototype.saveAddress = function saveAddress(id, addresses, callback) {
|
||||
for (i = 0; i < addresses.length; i++) {
|
||||
address = addresses[i];
|
||||
|
||||
hashes.push([address.getKeyHash('hex'), address]);
|
||||
path = Path.fromKeyRing(address);
|
||||
items.push([address.getKeyAddress(), path]);
|
||||
|
||||
if (address.type === 'multisig')
|
||||
hashes.push([address.getScriptHash('hex'), address]);
|
||||
if (address.type === 'multisig') {
|
||||
path = Path.fromKeyRing(address);
|
||||
items.push([address.getScriptAddress(), path]);
|
||||
}
|
||||
|
||||
if (address.witness)
|
||||
hashes.push([address.getProgramHash('hex'), address]);
|
||||
if (address.witness) {
|
||||
path = Path.fromKeyRing(address);
|
||||
items.push([address.getProgramAddress(), path]);
|
||||
}
|
||||
}
|
||||
|
||||
utils.forEachSerial(hashes, function(hash, next) {
|
||||
utils.forEachSerial(items, function(item, next) {
|
||||
var address = item[0];
|
||||
var path = item[1];
|
||||
var hash = address.getHash('hex');
|
||||
|
||||
if (self.tx.filter)
|
||||
self.tx.filter.add(hash[0], 'hex');
|
||||
self.tx.filter.add(hash, 'hex');
|
||||
|
||||
self.emit('save address', hash[0], hash[1]);
|
||||
self.emit('save address', address, path);
|
||||
|
||||
self.db.fetch('W/' + hash[0], parsePaths, function(err, paths) {
|
||||
self.db.fetch('W/' + hash, parsePaths, function(err, paths) {
|
||||
if (err)
|
||||
return next(err);
|
||||
|
||||
@ -784,9 +793,9 @@ WalletDB.prototype.saveAddress = function saveAddress(id, addresses, callback) {
|
||||
if (paths[id])
|
||||
return next();
|
||||
|
||||
paths[id] = Path.fromKeyRing(id, hash[1]);
|
||||
paths[id] = path;
|
||||
|
||||
batch.put('W/' + hash[0], serializePaths(paths));
|
||||
batch.put('W/' + hash, serializePaths(paths));
|
||||
|
||||
next();
|
||||
});
|
||||
@ -1294,8 +1303,8 @@ Path.prototype.toRaw = function toRaw(writer) {
|
||||
* @param {KeyRing} address
|
||||
*/
|
||||
|
||||
Path.prototype.fromKeyRing = function fromKeyRing(id, address) {
|
||||
this.id = id;
|
||||
Path.prototype.fromKeyRing = function fromKeyRing(address) {
|
||||
this.id = address.id;
|
||||
this.name = address.name;
|
||||
this.account = address.account;
|
||||
this.change = address.change;
|
||||
@ -1310,8 +1319,8 @@ Path.prototype.fromKeyRing = function fromKeyRing(id, address) {
|
||||
* @returns {Path}
|
||||
*/
|
||||
|
||||
Path.fromKeyRing = function fromKeyRing(id, address) {
|
||||
return new Path().fromKeyRing(id, address);
|
||||
Path.fromKeyRing = function fromKeyRing(address) {
|
||||
return new Path().fromKeyRing(address);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user