small fixes

This commit is contained in:
Matias Alejo Garcia 2014-04-22 22:07:18 -03:00
commit 31b2d5abac
5 changed files with 28 additions and 32 deletions

View file

@ -142,7 +142,7 @@ PublicKeyRing.prototype.getPubKeys = function (index, isChange) {
var bip32 = this.copayersBIP32[i].derive(path);
pubKeys[i] = bip32.eckey.public;
}
this.publicKeysCache[path] = pubKeys.map(function(pk){return pk.toString('hex')});
this.publicKeysCache[path] = pubKeys.map(function(pk){return pk.toString('hex');});
} else {
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex')});
}
@ -158,22 +158,30 @@ PublicKeyRing.prototype._checkIndexRange = function (index, isChange) {
}
};
// TODO this could be cached
PublicKeyRing.prototype.getRedeemScript = function (index, isChange) {
this._checkIndexRange(index, isChange);
var pubKeys = this.getPubKeys(index, isChange);
console.log('[PublicKeyRing.js.164:index:] getRedeemScript: ',index, isChange); //TODO
var script = Script.createMultisig(this.requiredCopayers, pubKeys);
return script;
};
// TODO this could be cached
PublicKeyRing.prototype.getAddress = function (index, isChange) {
this._checkIndexRange(index, isChange);
var script = this.getRedeemScript(index,isChange);
return Address.fromScript(script, this.network.name);
};
// TODO this could be cached
PublicKeyRing.prototype._addScriptMap = function (map, index, isChange) {
this._checkIndexRange(index, isChange);
var script = this.getRedeemScript(index,isChange);
map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex');
};
// TODO this could be cached
PublicKeyRing.prototype.getScriptPubKeyHex = function (index, isChange) {
this._checkIndexRange(index, isChange);
var addr = this.getAddress(index,isChange);
@ -181,7 +189,6 @@ PublicKeyRing.prototype.getScriptPubKeyHex = function (index, isChange) {
};
//generate a new address, update index.
PublicKeyRing.prototype.generateAddress = function(isChange) {
@ -216,11 +223,10 @@ PublicKeyRing.prototype.getRedeemScriptMap = function () {
var ret = {};
for (var i=0; i<this.changeAddressIndex; i++) {
ret[this.getAddress(i,true)] = this.getRedeemScript(i,true).getBuffer().toString('hex');
this._addScriptMap(ret,i,true);
}
for (var i=0; i<this.addressIndex; i++) {
ret[this.getAddress(i)] = this.getRedeemScript(i).getBuffer().toString('hex');
this._addScriptMap(ret,i,false);
}
return ret;
};