mirror of https://github.com/BTCPrivate/copay.git
add cache to pubkeyring test. Speedup 2x
This commit is contained in:
parent
c19eac6a4e
commit
4e6d572de0
|
@ -23,8 +23,7 @@ function PublicKeyRing(opts) {
|
||||||
|
|
||||||
this.copayersHK = opts.copayersHK || [];
|
this.copayersHK = opts.copayersHK || [];
|
||||||
|
|
||||||
this.indexes = opts.indexes ? HDParams.fromList(opts.indexes)
|
this.indexes = opts.indexes ? HDParams.fromList(opts.indexes) : HDParams.init(this.totalCopayers);
|
||||||
: HDParams.init(this.totalCopayers);
|
|
||||||
|
|
||||||
this.publicKeysCache = opts.publicKeysCache || {};
|
this.publicKeysCache = opts.publicKeysCache || {};
|
||||||
this.nicknameFor = opts.nicknameFor || {};
|
this.nicknameFor = opts.nicknameFor || {};
|
||||||
|
@ -192,7 +191,9 @@ PublicKeyRing.prototype.getAddress = function(index, isChange, id) {
|
||||||
// Overloaded to receive a PubkeyString or a consigner index
|
// Overloaded to receive a PubkeyString or a consigner index
|
||||||
PublicKeyRing.prototype.getHDParams = function(id) {
|
PublicKeyRing.prototype.getHDParams = function(id) {
|
||||||
var copayerIndex = this.getCosigner(id);
|
var copayerIndex = this.getCosigner(id);
|
||||||
var index = this.indexes.filter(function(i) { return i.copayerIndex == copayerIndex });
|
var index = this.indexes.filter(function(i) {
|
||||||
|
return i.copayerIndex == copayerIndex
|
||||||
|
});
|
||||||
if (index.length != 1) throw new Error('no index for copayerIndex');
|
if (index.length != 1) throw new Error('no index for copayerIndex');
|
||||||
|
|
||||||
return index[0];
|
return index[0];
|
||||||
|
@ -233,7 +234,9 @@ PublicKeyRing.prototype.getCosigner = function(pubKey) {
|
||||||
|
|
||||||
var sorted = this.copayersHK.map(function(h, i) {
|
var sorted = this.copayersHK.map(function(h, i) {
|
||||||
return h.eckey.public.toString('hex');
|
return h.eckey.public.toString('hex');
|
||||||
}).sort(function(h1, h2){ return h1.localeCompare(h2); });
|
}).sort(function(h1, h2) {
|
||||||
|
return h1.localeCompare(h2);
|
||||||
|
});
|
||||||
|
|
||||||
var index = sorted.indexOf(pubKey);
|
var index = sorted.indexOf(pubKey);
|
||||||
if (index == -1) throw new Error('no public key in ring');
|
if (index == -1) throw new Error('no public key in ring');
|
||||||
|
@ -255,8 +258,7 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts, pubkey) {
|
||||||
PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, copayerIndex) {
|
PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, copayerIndex) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
var isOwned = index.copayerIndex == HDPath.SHARED_INDEX
|
var isOwned = index.copayerIndex == HDPath.SHARED_INDEX || index.copayerIndex == copayerIndex;
|
||||||
|| index.copayerIndex == copayerIndex;
|
|
||||||
|
|
||||||
var ret = [];
|
var ret = [];
|
||||||
if (!opts.excludeChange) {
|
if (!opts.excludeChange) {
|
||||||
|
@ -286,10 +288,21 @@ PublicKeyRing.prototype.getAddressesInfoForIndex = function(index, opts, copayer
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PublicKeyRing.prototype.getForPaths = function(paths) {
|
||||||
|
return paths.map(this.getForPath.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
PublicKeyRing.prototype.getForPath = function(path) {
|
||||||
|
var p = HDPath.indexesForPath(path);
|
||||||
|
var pubKeys = this.getPubKeys(p.addressIndex, p.isChange, p.copayerIndex);
|
||||||
|
return pubKeys;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// TODO this could be cached
|
// TODO this could be cached
|
||||||
PublicKeyRing.prototype._addScriptMap = function(map, path) {
|
PublicKeyRing.prototype._addScriptMap = function(map, path) {
|
||||||
var p = HDPath.indicesForPath(path);
|
var p = HDPath.indexesForPath(path);
|
||||||
var script = this.getRedeemScript(p.index, p.isChange, p.copayerIndex);
|
var script = this.getRedeemScript(p.addressIndex, p.isChange, p.copayerIndex);
|
||||||
map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex');
|
map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue