many optimizations in addresses pulling
This commit is contained in:
parent
425703c447
commit
398daf3f05
9 changed files with 183 additions and 130 deletions
|
|
@ -79,7 +79,7 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
|||
recipients = null;
|
||||
this.sendPublicKeyRing(recipients);
|
||||
}
|
||||
this.emit('refresh', this.publicKeyRing);
|
||||
this.emit('publicKeyRingUpdated');
|
||||
this.store();
|
||||
};
|
||||
|
||||
|
|
@ -222,11 +222,13 @@ Wallet.prototype.netStart = function() {
|
|||
if (this.publicKeyRing.isComplete()) {
|
||||
this._lockIncomming();
|
||||
}
|
||||
|
||||
net.start(startOpts, function() {
|
||||
self.connectToAll();
|
||||
self.emit('ready', net.getPeer());
|
||||
self.emit('refresh');
|
||||
setTimeout(function(){
|
||||
self.emit('publicKeyRingUpdated');
|
||||
self.connectToAll();
|
||||
self.emit('txProposalsUpdated');
|
||||
},10);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -346,11 +348,20 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
|||
});
|
||||
};
|
||||
|
||||
Wallet.prototype.getName = function() {
|
||||
return this.name || this.id;
|
||||
};
|
||||
|
||||
Wallet.prototype.generateAddress = function(isChange) {
|
||||
var addr = this.publicKeyRing.generateAddress(isChange);
|
||||
Wallet.prototype._doGenerateAddress = function(isChange) {
|
||||
return this.publicKeyRing.generateAddress(isChange);
|
||||
};
|
||||
|
||||
|
||||
Wallet.prototype.generateAddress = function(isChange, cb) {
|
||||
var addr = this._doGenerateAddress(isChange);
|
||||
this.sendPublicKeyRing();
|
||||
this.store();
|
||||
if (cb) return cb(addr);
|
||||
return addr;
|
||||
};
|
||||
|
||||
|
|
@ -383,27 +394,30 @@ Wallet.prototype.reject = function(ntxid) {
|
|||
};
|
||||
|
||||
|
||||
Wallet.prototype.sign = function(ntxid) {
|
||||
Wallet.prototype.sign = function(ntxid, cb) {
|
||||
var self = this;
|
||||
var myId = this.getMyCopayerId();
|
||||
var txp = self.txProposals.txps[ntxid];
|
||||
if (!txp || txp.rejectedBy[myId] || txp.signedBy[myId]) return;
|
||||
setTimeout(function() {
|
||||
var myId = self.getMyCopayerId();
|
||||
var txp = self.txProposals.txps[ntxid];
|
||||
if (!txp || txp.rejectedBy[myId] || txp.signedBy[myId]) return;
|
||||
|
||||
var pkr = self.publicKeyRing;
|
||||
var keys = self.privateKey.getAll(pkr.addressIndex, pkr.changeAddressIndex);
|
||||
var pkr = self.publicKeyRing;
|
||||
var keys = self.privateKey.getAll(pkr.addressIndex, pkr.changeAddressIndex);
|
||||
|
||||
var b = txp.builder;
|
||||
var before = b.signaturesAdded;
|
||||
b.sign(keys);
|
||||
var b = txp.builder;
|
||||
var before = b.signaturesAdded;
|
||||
b.sign(keys);
|
||||
|
||||
if (b.signaturesAdded > before) {
|
||||
txp.signedBy[myId] = Date.now();
|
||||
this.sendTxProposals(null, ntxid);
|
||||
this.store();
|
||||
this.emit('txProposalsUpdated');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
var ret = false;
|
||||
if (b.signaturesAdded > before) {
|
||||
txp.signedBy[myId] = Date.now();
|
||||
self.sendTxProposals(null, ntxid);
|
||||
self.store();
|
||||
self.emit('txProposalsUpdated');
|
||||
ret = true;
|
||||
}
|
||||
if (cb) return cb(ret);
|
||||
},10);
|
||||
};
|
||||
|
||||
Wallet.prototype.sendTx = function(ntxid, cb) {
|
||||
|
|
@ -423,9 +437,9 @@ Wallet.prototype.sendTx = function(ntxid, cb) {
|
|||
self.log('BITCOND txid:', txid); //TODO
|
||||
if (txid) {
|
||||
self.txProposals.setSent(ntxid, txid);
|
||||
self.sendTxProposals(null, ntxid);
|
||||
self.store();
|
||||
}
|
||||
self.sendTxProposals(null, ntxid);
|
||||
self.store();
|
||||
return cb(txid);
|
||||
});
|
||||
};
|
||||
|
|
@ -536,7 +550,7 @@ Wallet.prototype.createTx = function(toAddress, amountSatStr, opts, cb) {
|
|||
self.getUnspent(function(safeUnspent) {
|
||||
var ntxid = self.createTxSync(toAddress, amountSatStr, safeUnspent, opts);
|
||||
if (ntxid) {
|
||||
self.sendPublicKeyRing(); // For the new change Address
|
||||
self.sendPublicKeyRing();
|
||||
self.sendTxProposals(null, ntxid);
|
||||
self.store();
|
||||
self.emit('txProposalsUpdated');
|
||||
|
|
@ -558,7 +572,7 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, utxos, opts) {
|
|||
|
||||
if (!opts.remainderOut) {
|
||||
opts.remainderOut = {
|
||||
address: this.generateAddress(true).toString()
|
||||
address: this._doGenerateAddress(true).toString()
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue