make explicit refreshes when storing wallet
This commit is contained in:
parent
de1464f95d
commit
22cd4cae94
2 changed files with 25 additions and 29 deletions
|
|
@ -9,8 +9,8 @@ var Builder = bitcore.TransactionBuilder;
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
var EventEmitter = imports.EventEmitter || require('events').EventEmitter;
|
||||||
var copay = copay || require('../../../copay');
|
var copay = copay || require('../../../copay');
|
||||||
var SecureRandom = bitcore.SecureRandom;
|
var SecureRandom = bitcore.SecureRandom;
|
||||||
var Base58Check = bitcore.Base58.base58Check;
|
var Base58Check = bitcore.Base58.base58Check;
|
||||||
|
|
||||||
function Wallet(opts) {
|
function Wallet(opts) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
@ -81,7 +81,7 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
||||||
this.log('RECV TXPROPOSAL:', data);
|
this.log('RECV TXPROPOSAL:', data);
|
||||||
|
|
||||||
var recipients;
|
var recipients;
|
||||||
var inTxp = copay.TxProposals.fromObj(data.txProposals);
|
var inTxp = copay.TxProposals.fromObj(data.txProposals);
|
||||||
|
|
@ -127,7 +127,6 @@ Wallet.prototype._handleNetworkChange = function(newCopayerId) {
|
||||||
this.sendWalletId(newCopayerId);
|
this.sendWalletId(newCopayerId);
|
||||||
this.emit('peer', this.network.peerFromCopayer(newCopayerId));
|
this.emit('peer', this.network.peerFromCopayer(newCopayerId));
|
||||||
}
|
}
|
||||||
this.emit('refresh');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -156,9 +155,9 @@ Wallet.prototype.getMyCopayerId = function() {
|
||||||
|
|
||||||
|
|
||||||
Wallet.prototype.getSecret = function() {
|
Wallet.prototype.getSecret = function() {
|
||||||
var i = new Buffer(this.getMyCopayerId(),'hex');
|
var i = new Buffer(this.getMyCopayerId(), 'hex');
|
||||||
var k = new Buffer(this.netKey,'base64');
|
var k = new Buffer(this.netKey, 'base64');
|
||||||
var b = Buffer.concat([i,k]);
|
var b = Buffer.concat([i, k]);
|
||||||
var str = Base58Check.encode(b);
|
var str = Base58Check.encode(b);
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
@ -167,7 +166,7 @@ Wallet.prototype.getSecret = function() {
|
||||||
Wallet.decodeSecret = function(secretB) {
|
Wallet.decodeSecret = function(secretB) {
|
||||||
var secret = Base58Check.decode(secretB);
|
var secret = Base58Check.decode(secretB);
|
||||||
var netKeyBuf = secret.slice(-8);
|
var netKeyBuf = secret.slice(-8);
|
||||||
var pubKeyBuf = secret.slice(0,33);
|
var pubKeyBuf = secret.slice(0, 33);
|
||||||
return {
|
return {
|
||||||
pubKey: pubKeyBuf.toString('hex'),
|
pubKey: pubKeyBuf.toString('hex'),
|
||||||
netKey: netKeyBuf.toString('base64'),
|
netKey: netKeyBuf.toString('base64'),
|
||||||
|
|
@ -231,17 +230,10 @@ Wallet.prototype.getRegisteredPeerIds = function() {
|
||||||
return this.registeredPeerIds;
|
return this.registeredPeerIds;
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.store = function(isSync) {
|
Wallet.prototype.store = function() {
|
||||||
var wallet = this.toObj();
|
var wallet = this.toObj();
|
||||||
this.storage.setFromObj(this.id, wallet);
|
this.storage.setFromObj(this.id, wallet);
|
||||||
|
this.log('Wallet stored');
|
||||||
if (isSync) {
|
|
||||||
this.log('Wallet stored.'); //TODO
|
|
||||||
} else {
|
|
||||||
this.log('Wallet stored. REFRESH Emitted'); //TODO
|
|
||||||
this.emit('refresh');
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.toObj = function() {
|
Wallet.prototype.toObj = function() {
|
||||||
|
|
@ -257,14 +249,14 @@ Wallet.prototype.toObj = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.fromObj = function(o, storage, network, blockchain) {
|
Wallet.fromObj = function(o, storage, network, blockchain) {
|
||||||
var opts = JSON.parse(JSON.stringify(o.opts));
|
var opts = JSON.parse(JSON.stringify(o.opts));
|
||||||
opts.publicKeyRing = copay.PublicKeyRing.fromObj(o.publicKeyRing);
|
opts.publicKeyRing = copay.PublicKeyRing.fromObj(o.publicKeyRing);
|
||||||
opts.txProposals = copay.TxProposals.fromObj(o.txProposals);
|
opts.txProposals = copay.TxProposals.fromObj(o.txProposals);
|
||||||
opts.privateKey = copay.PrivateKey.fromObj(o.privateKey);
|
opts.privateKey = copay.PrivateKey.fromObj(o.privateKey);
|
||||||
|
|
||||||
opts.storage = storage;
|
opts.storage = storage;
|
||||||
opts.network = network;
|
opts.network = network;
|
||||||
opts.blockchain = blockchain;
|
opts.blockchain = blockchain;
|
||||||
var w = new Wallet(opts);
|
var w = new Wallet(opts);
|
||||||
return w;
|
return w;
|
||||||
};
|
};
|
||||||
|
|
@ -319,7 +311,8 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
||||||
Wallet.prototype.generateAddress = function(isChange) {
|
Wallet.prototype.generateAddress = function(isChange) {
|
||||||
var addr = this.publicKeyRing.generateAddress(isChange);
|
var addr = this.publicKeyRing.generateAddress(isChange);
|
||||||
this.sendPublicKeyRing();
|
this.sendPublicKeyRing();
|
||||||
this.store(true);
|
this.store();
|
||||||
|
this.emit('refresh');
|
||||||
return addr;
|
return addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -346,7 +339,8 @@ Wallet.prototype.reject = function(ntxid) {
|
||||||
|
|
||||||
txp.rejectedBy[myId] = Date.now();
|
txp.rejectedBy[myId] = Date.now();
|
||||||
this.sendTxProposals();
|
this.sendTxProposals();
|
||||||
this.store(true);
|
this.store();
|
||||||
|
this.emit('refresh');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -363,14 +357,14 @@ Wallet.prototype.sign = function(ntxid) {
|
||||||
var before = b.signaturesAdded;
|
var before = b.signaturesAdded;
|
||||||
b.sign(keys);
|
b.sign(keys);
|
||||||
|
|
||||||
var ret = false;
|
|
||||||
if (b.signaturesAdded > before) {
|
if (b.signaturesAdded > before) {
|
||||||
txp.signedBy[myId] = Date.now();
|
txp.signedBy[myId] = Date.now();
|
||||||
this.sendTxProposals();
|
this.sendTxProposals();
|
||||||
this.store(true);
|
this.store();
|
||||||
ret = true;
|
this.emit('refresh');
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return ret;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Wallet.prototype.sendTx = function(ntxid, cb) {
|
Wallet.prototype.sendTx = function(ntxid, cb) {
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ angular.module('copay.controllerUtils')
|
||||||
$location.path('addresses');
|
$location.path('addresses');
|
||||||
});
|
});
|
||||||
w.on('refresh', function() {
|
w.on('refresh', function() {
|
||||||
|
//alert('refresh');
|
||||||
root.updateBalance(function() {
|
root.updateBalance(function() {
|
||||||
$rootScope.$digest();
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
|
|
@ -93,6 +94,7 @@ angular.module('copay.controllerUtils')
|
||||||
w.on('openError', root.onErrorDigest);
|
w.on('openError', root.onErrorDigest);
|
||||||
w.on('peer', function(peerID) {
|
w.on('peer', function(peerID) {
|
||||||
video.callPeer(peerID, handlePeerVideo);
|
video.callPeer(peerID, handlePeerVideo);
|
||||||
|
$rootScope.$digest();
|
||||||
});
|
});
|
||||||
w.on('close', root.onErrorDigest);
|
w.on('close', root.onErrorDigest);
|
||||||
w.netStart();
|
w.netStart();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue