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

@ -71,9 +71,6 @@ PrivateKey.prototype.get = function(index,isChange) {
PrivateKey.prototype.getAll = function(addressIndex, changeAddressIndex) {
var ret = [];
console.log('[PrivateKey.js.75:addressIndex:]',addressIndex); //TODO
console.log('[PrivateKey.js.79:changeAddressIndex:]',changeAddressIndex); //TODO
for(var i=0;i<addressIndex; i++) {
ret.push(this.get(i,false));
}

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;
};

View file

@ -269,7 +269,6 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
Wallet.prototype.generateAddress = function(isChange) {
var addr = this.publicKeyRing.generateAddress(isChange);
console.log('[Wallet.js.281:addr:]',addr, this.publicKeyRing.toObj(), this.getAddresses()); //TODO
this.sendPublicKeyRing();
this.store(true);
return addr;
@ -318,7 +317,6 @@ Wallet.prototype.sign = function(ntxid) {
var pkr = self.publicKeyRing;
var keys = self.privateKey.getAll(pkr.addressIndex, pkr.changeAddressIndex);
console.log('[Wallet.js.329:keys:] LENGTH::',keys.length, pkr.addressIndex, pkr.changeAddressIndex); //TODO
var b = txp.builder;
var before = b.signaturesAdded;
@ -465,11 +463,11 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
}
self.getSafeUnspent(function(unspentList) {
// TODO check enough funds, etc.
self.createTxSync(toAddress, amountSatStr, unspentList, opts);
self.sendPublicKeyRing(); // Change Address
self.sendTxProposals();
self.store();
if (self.createTxSync(toAddress, amountSatStr, unspentList, opts)) {
self.sendPublicKeyRing(); // Change Address
self.sendTxProposals();
self.store();
}
return cb();
});
};
@ -497,11 +495,8 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
var signRet;
if (priv) {
var keys = priv.getAll(pkr.addressIndex, pkr.changeAddressIndex);
console.log('[Wallet.js.329:keys:] LENGTH::',keys.length, pkr.addressIndex, pkr.changeAddressIndex); //TODO
b.sign( keys );
b.sign( priv.getAll(pkr.addressIndex, pkr.changeAddressIndex) );
}
console.log('[Wallet.js.494]', b, b.build().serialize().toString('hex')); //TODO
var me = {};
var myId = this.getMyPeerId();
var now = Date.now();

View file

@ -261,7 +261,6 @@ console.log('[WebRTC.js.255] WARN: NO CONNECTION TO:', peerId); //TODO
Network.prototype.send = function(peerIds, data, cb) {
var self=this;
console.log('[WebRTC.js.242] SENDING ', data.type); //TODO
if (!peerIds) {
peerIds = this.connectedPeers;
data.isBroadcast = 1;