fix history sync

This commit is contained in:
Matias Alejo Garcia 2015-11-10 20:05:05 -03:00
parent 1e9b99981e
commit 232b78ee8c
12 changed files with 95 additions and 72 deletions

View File

@ -8,7 +8,7 @@
], ],
"dependencies": { "dependencies": {
"angular": "1.4.6", "angular": "1.4.6",
"angular-bitcore-wallet-client": "1.1.5", "angular-bitcore-wallet-client": "1.1.6",
"angular-foundation": "0.7.0", "angular-foundation": "0.7.0",
"angular-gettext": "2.1.0", "angular-gettext": "2.1.0",
"angular-moment": "0.10.1", "angular-moment": "0.10.1",

View File

@ -1,11 +1,16 @@
<span ng-show="index.isShared"><span translate>{{index.m}}-of-{{index.n}}</span></span> <span ng-show="index.isShared"><span translate>{{index.m}}-of-{{index.n}}</span></span>
<img style="height:1em" ng-show="index.network != 'livenet'" src="img/icon-testnet.svg"> <img style="height:1em" ng-show="index.network != 'livenet'" src="img/icon-testnet.svg">
<img style="height:1em" ng-show="!index.canSign && !index.isPrivKeyExternal" src="img/icon-view.svg"> <img style="height:1em" ng-show="!index.canSign && !index.isPrivKeyExternal" src="img/icon-read-only.svg">
<img style="height:1em" ng-show="index.externalSource == 'trezor'" src="img/icon-trezor.svg"> <img style="height:1em" ng-show="index.externalSource == 'trezor'" src="img/icon-trezor.svg">
<img style="height:1em" ng-show="index.externalSource == 'ledger'" src="img/icon-ledger.svg">
<span style="height:1em" ng-show="index.account">#{{index.account || 0}} </span> <span style="height:1em" ng-show="index.account">#{{index.account || 0}} </span>
<img style="height:1em" ng-show="index.isPrivKeyEncrypted" src="img/icon-lock.svg"> <img style="height:1em" ng-show="index.isPrivKeyEncrypted" src="img/icon-lock.svg">
<img style="height:1em" ng-show="index.preferences.email" src="img/icon-email.svg"> <!-- <img style="height:1em" ng&#45;show="index.preferences.email" src="img/icon&#45;email.svg"> -->
<img style="height:1em" ng-show="index.usingCustomBWS" src="img/icon-bws.svg">
<img style="height:1em" class="animated flash infinite" ng-show="index.updatingTxHistory[index.walletId]" src="img/icon-sync.svg">

View File

@ -442,7 +442,7 @@
--> -->
<div id="history" class="history tab-view"> <div id="history" class="history tab-view">
<div class="row m20t" ng-show="!index.txHistory[0] && !index.updatingTxHistory"> <div class="row m20t" ng-show="!index.txHistory[0] && !index.updatingTxHistory[index.walletId]">
<div class="large-12 columns"> <div class="large-12 columns">
<div class="oh text-center"> <div class="oh text-center">
<span ng-show="index.txHistoryError && !index.notAuthorized" ng-click='index.updateTxHistory()'> <span ng-show="index.txHistoryError && !index.notAuthorized" ng-click='index.updateTxHistory()'>
@ -455,7 +455,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row m20t text-center" ng-show="index.updatingtxhistory"> <div class="row m20t text-center" ng-show="index.updatingTxHistory[index.walletId]">
<div class="columns large-12 medium-12 small-12"> <div class="columns large-12 medium-12 small-12">
<div class="spinner"> <div class="spinner">
<div class="rect1"></div> <div class="rect1"></div>
@ -465,11 +465,11 @@
<div class="rect5"></div> <div class="rect5"></div>
</div> </div>
</div> </div>
<div ng-show="index.showWaitingSign" translate class="size-12 text-gray m20t"> <div ng-show="index.txProgress > 6" translate class="size-12 text-gray m20t">
Initial transaction history synchronization can take some minutes for wallets with many transactions.</br> Initial transaction history synchronization can take some minutes for wallets with many transactions.</br>
Please stand by. Please stand by.
</div> </div>
<div ng-show="index.showWaitingSign" translate class="size-14 text-gray m20t"> <div ng-show="index.txProgress > 6" translate class="size-14 text-gray m20t">
<b>{{index.txProgress}}</b> Transactions<br> <b>{{index.txProgress}}</b> Transactions<br>
Downloaded Downloaded
</div> </div>

View File

@ -96,7 +96,6 @@ angular.module('copayApp.controllers').controller('createController',
myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null, myName: $scope.totalCopayers > 1 ? form.myName.$modelValue : null,
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet', networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
bwsurl: $scope.bwsurl, bwsurl: $scope.bwsurl,
use48: $scope.fromHardware,
}; };
var setSeed = self.seedSourceId == 'set'; var setSeed = self.seedSourceId == 'set';
if (setSeed) { if (setSeed) {

View File

@ -8,6 +8,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.isSafari = isMobile.Safari(); self.isSafari = isMobile.Safari();
self.onGoingProcess = {}; self.onGoingProcess = {};
self.historyShowLimit = 10; self.historyShowLimit = 10;
self.updatingTxHistory = {};
function strip(number) { function strip(number) {
return (parseFloat(number.toPrecision(12))); return (parseFloat(number.toPrecision(12)));
@ -123,6 +124,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.initGlidera(); self.initGlidera();
self.setCustomBWSFlag();
if (fc.isPrivKeyExternal()) { if (fc.isPrivKeyExternal()) {
self.needsBackup = false; self.needsBackup = false;
self.openWallet(); self.openWallet();
@ -135,6 +137,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.setCustomBWSFlag = function() {
var defaults = configService.getDefaults();
var config = configService.getSync();
self.usingCustomBWS = config.bwsFor && (config.bwsFor[self.walletId] != defaults.bws.url);
};
self.setTab = function(tab, reset, tries, switchState) { self.setTab = function(tab, reset, tries, switchState) {
tries = tries || 0; tries = tries || 0;
@ -753,17 +762,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
} }
self.getConfirmedTxs = function(cb) { self.getConfirmedTxs = function(walletId, cb) {
var fc = profileService.focusedClient;
var c = fc.credentials;
storageService.getTxHistory(c.walletId, function(err, txs) { storageService.getTxHistory(walletId, function(err, txs) {
if (err) return cb(err); if (err) return cb(err);
var localTxs = []; var localTxs = [];
if (!txs) { if (!txs) {
self.showWaitingSign = true;
return cb(null, localTxs); return cb(null, localTxs);
} }
@ -776,20 +782,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
} }
self.updateLocalTxHistory = function(cb) { self.updateLocalTxHistory = function(client, cb) {
var requestLimit = 6; var requestLimit = 6;
var walletId = client.credentials.walletId;
self.getConfirmedTxs(function(err, txsFromLocal) { self.getConfirmedTxs(walletId, function(err, txsFromLocal) {
if (err) return cb(err); if (err) return cb(err);
var endingTxid = txsFromLocal[0] ? txsFromLocal[0].txid : null; var endingTxid = txsFromLocal[0] ? txsFromLocal[0].txid : null;
function getNewTxs(newTxs, skip, i_cb) { function getNewTxs(newTxs, skip, i_cb) {
self.getTxsFromServer(skip, endingTxid, requestLimit, function(err, res, shouldContinue) { self.getTxsFromServer(client, skip, endingTxid, requestLimit, function(err, res, shouldContinue) {
if (err) return i_cb(err); if (err) return i_cb(err);
newTxs = newTxs.concat(res); newTxs = newTxs.concat(lodash.compact(res));
skip = skip + requestLimit; skip = skip + requestLimit;
$log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue); $log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue);
@ -800,8 +807,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
return i_cb(null, newTxs); return i_cb(null, newTxs);
} }
self.txProgress = newTxs.length; if (walletId == profileService.focusedClient.credentials.walletId)
$timeout(function(){ self.txProgress = newTxs.length;
$timeout(function() {
$rootScope.$apply(); $rootScope.$apply();
}); });
getNewTxs(newTxs, skip, i_cb); getNewTxs(newTxs, skip, i_cb);
@ -814,13 +823,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var newHistory = lodash.compact(txs.concat(txsFromLocal)); var newHistory = lodash.compact(txs.concat(txsFromLocal));
$log.debug('Tx History synced. Total Txs: ' + newHistory.length); $log.debug('Tx History synced. Total Txs: ' + newHistory.length);
self.completeHistory = newHistory; if (walletId == profileService.focusedClient.credentials.walletId) {
self.txHistory = newHistory.slice(0, self.historyShowLimit); self.completeHistory = newHistory;
self.historyShowShowAll = newHistory.length >= self.historyShowLimit; self.txHistory = newHistory.slice(0, self.historyShowLimit);
self.historyShowShowAll = newHistory.length >= self.historyShowLimit;
}
var fc = profileService.focusedClient; return storageService.setTxHistory(JSON.stringify(newHistory), walletId, function() {
var c = fc.credentials;
return storageService.setTxHistory(JSON.stringify(newHistory), c.walletId, function() {
return cb(); return cb();
}); });
}); });
@ -838,11 +847,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.getTxsFromServer = function(skip, endingTxid, limit, cb) { self.getTxsFromServer = function(client, skip, endingTxid, limit, cb) {
var res = []; var res = [];
var fc = profileService.focusedClient; client.getTxHistory({
fc.getTxHistory({
skip: skip, skip: skip,
limit: limit limit: limit
}, function(err, txsFromServer) { }, function(err, txsFromServer) {
@ -861,18 +869,18 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateHistory = function() { self.updateHistory = function() {
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
if (!fc.isComplete() || self.updatingTxHistory) return; var walletId = fc.credentials.walletId;
if (!fc.isComplete() || self.updatingTxHistory[walletId]) return;
$log.debug('Updating Transaction History'); $log.debug('Updating Transaction History');
self.txHistoryError = false; self.txHistoryError = false;
self.updatingTxHistory = true; self.updatingTxHistory[walletId] = true;
$timeout(function() { $timeout(function() {
self.updateLocalTxHistory(function(err) { self.updateLocalTxHistory(fc, function(err) {
self.updatingTxHistory = false; self.updatingTxHistory[walletId] = false;
self.showWaitingSign = false; if (err)
if (err)
self.txHistoryError = true; self.txHistoryError = true;
$rootScope.$apply(); $rootScope.$apply();
@ -1325,4 +1333,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setFocusedWallet(); self.setFocusedWallet();
}); });
}); });
$rootScope.$on('Local/NewEncryptionSetting', function() {
var fc = profileService.focusedClient;
self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
$timeout(function() {
$rootScope.$apply();
});
});
}); });

View File

@ -55,6 +55,7 @@ angular.module('copayApp.controllers').controller('preferencesController',
return; return;
} }
profileService.setPrivateKeyEncryptionFC(password, function() { profileService.setPrivateKeyEncryptionFC(password, function() {
$rootScope.$emit('Local/NewEncryptionSetting');
$scope.encrypt = true; $scope.encrypt = true;
}); });
}); });
@ -66,6 +67,7 @@ angular.module('copayApp.controllers').controller('preferencesController',
return; return;
} }
profileService.disablePrivateKeyEncryptionFC(function(err) { profileService.disablePrivateKeyEncryptionFC(function(err) {
$rootScope.$emit('Local/NewEncryptionSetting');
if (err) { if (err) {
$scope.encrypt = true; $scope.encrypt = true;
$log.error(err); $log.error(err);

View File

@ -13,7 +13,7 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
this.bwsurl = (config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url; this.bwsurl = (config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url;
this.resetDefaultUrl = function() { this.resetDefaultUrl = function() {
this.bwsurl = 'https://bws.bitpay.com/bws/api'; this.bwsurl = defaults.bws.url;
}; };
this.save = function() { this.save = function() {
@ -50,4 +50,4 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
}); });
}); });
}; };
}); });

View File

@ -7,7 +7,7 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
var c = fc.credentials; var c = fc.credentials;
this.init = function() { this.init = function() {
var basePath = profileService.getUtils().getBaseAddressDerivationPath(c.derivationStrategy, c.network, c.account); var basePath = c.getBaseAddressDerivationPath();
$scope.walletName = c.walletName; $scope.walletName = c.walletName;
$scope.walletId = c.walletId; $scope.walletId = c.walletId;

View File

@ -16,28 +16,28 @@ angular.module('copayApp.services')
return msg; return msg;
}; };
root.getAddressPath = function(isMultisig, account) {
var rootPath;
if (account) { root.getRootPath = function(device, isMultisig, account) {
rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH; if (!isMultisig) return root.UNISIG_ROOTPATH;
} else {
// Old ledger wallet compat // Compat
rootPath = 44; if (device == 'ledger' && account ==0) return root.UNISIG_ROOTPATH;
}
return rootPath + "'/" + root.LIVENET_PATH + "'/" + account + "'"; return root.MULTISIG_ROOTPATH;
};
root.getAddressPath = function(device, isMultisig, account) {
return root.getRootPath(device,isMultisig,account) + "'/" + root.LIVENET_PATH + "'/" + account + "'";
} }
root.getEntropyPath = function(isMultisig, account) { root.getEntropyPath = function(device, isMultisig, account) {
var path; var path;
if (account) {
var rootPath = isMultisig ? root.MULTISIG_ROOTPATH : root.UNISIG_ROOTPATH; // Old ledger wallet compat
path = root.ENTROPY_INDEX_PATH + rootPath + "'/" + account + "'"; if (device == 'ledger' && account == 0)
} else { return root.ENTROPY_INDEX_PATH + "0'";
// Old ledger wallet compat
path = root.ENTROPY_INDEX_PATH + "0'"; return root.ENTROPY_INDEX_PATH + root.getRootPath(device,isMultisig,account) + "'/" + account + "'";
}
return path;
}; };
root.pubKeyToEntropySource = function(xPubKey) { root.pubKeyToEntropySource = function(xPubKey) {

View File

@ -13,7 +13,7 @@ angular.module('copayApp.services')
} }
root.getEntropySource = function(isMultisig, account, callback) { root.getEntropySource = function(isMultisig, account, callback) {
root.getXPubKey(hwWallet.getEntropyPath(isMultisig, account), function(data) { root.getXPubKey(hwWallet.getEntropyPath('ledger', isMultisig, account), function(data) {
if (!data.success) if (!data.success)
return callback(hwWallet._err(data)); return callback(hwWallet._err(data));
@ -37,7 +37,7 @@ angular.module('copayApp.services')
if (err) return callback(err); if (err) return callback(err);
opts.entropySource = entropySource; opts.entropySource = entropySource;
root.getXPubKey(hwWallet.getAddressPath(isMultisig, account), function(data) { root.getXPubKey(hwWallet.getAddressPath('ledger', isMultisig, account), function(data) {
if (!data.success) { if (!data.success) {
$log.warn(data.message); $log.warn(data.message);
return callback(data); return callback(data);
@ -45,6 +45,9 @@ angular.module('copayApp.services')
opts.extendedPublicKey = data.xpubkey; opts.extendedPublicKey = data.xpubkey;
opts.externalSource = 'ledger'; opts.externalSource = 'ledger';
opts.account = account; opts.account = account;
// Old ledger compat
opts.derivationStrategy = account ? 'BIP48' : 'BIP44';
return callback(null, opts); return callback(null, opts);
}); });
}); });
@ -54,11 +57,10 @@ angular.module('copayApp.services')
root.callbacks["sign_p2sh"] = callback; root.callbacks["sign_p2sh"] = callback;
var redeemScripts = []; var redeemScripts = [];
var paths = []; var paths = [];
var tx = bwcService.buildTx(txp);
var tx = bwcService.getUtils().buildTx(txp);
for (var i = 0; i < tx.inputs.length; i++) { for (var i = 0; i < tx.inputs.length; i++) {
redeemScripts.push(new ByteString(tx.inputs[i].redeemScript.toBuffer().toString('hex'), GP.HEX).toString()); redeemScripts.push(new ByteString(tx.inputs[i].redeemScript.toBuffer().toString('hex'), GP.HEX).toString());
paths.push(hwWallet.getAddressPath(isMultisig, account) + txp.inputs[i].path.substring(1)); paths.push(hwWallet.getAddressPath('ledger', isMultisig, account) + txp.inputs[i].path.substring(1));
} }
var splitTransaction = root._splitTransaction(new ByteString(tx.toString(), GP.HEX)); var splitTransaction = root._splitTransaction(new ByteString(tx.toString(), GP.HEX));
var inputs = []; var inputs = [];

View File

@ -173,12 +173,6 @@ angular.module('copayApp.services')
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
var network = opts.networkName || 'livenet'; var network = opts.networkName || 'livenet';
// TODO refactor this and use bwc contants?
var derivationStrategy = 'BIP44';
if (opts.fromHardware && opts.n > 1) {
derivationStrategy = 'BIP48';
}
if (opts.mnemonic) { if (opts.mnemonic) {
try { try {
@ -187,7 +181,7 @@ angular.module('copayApp.services')
network: network, network: network,
passphrase: opts.passphrase, passphrase: opts.passphrase,
account: opts.account || 0, account: opts.account || 0,
derivationStrategy: derivationStrategy, derivationStrategy: opts.derivationStrategy || 'BIP44',
}); });
} catch (ex) { } catch (ex) {
@ -205,7 +199,7 @@ angular.module('copayApp.services')
try { try {
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
account: opts.account || 0, account: opts.account || 0,
derivationStrategy: derivationStrategy, derivationStrategy: opts.derivationStrategy || 'BIP44',
}); });
} catch (ex) { } catch (ex) {
$log.warn("Creating wallet from Extended Public Key Arg:", ex, opts); $log.warn("Creating wallet from Extended Public Key Arg:", ex, opts);
@ -319,7 +313,7 @@ angular.module('copayApp.services')
walletId: walletId walletId: walletId
}); });
delete root.walletClients[walletId]; delete root.walletClients[walletId];
root.focusedClient = null; root.focusedClient = null;
storageService.clearLastAddress(walletId, function(err) { storageService.clearLastAddress(walletId, function(err) {
@ -446,6 +440,7 @@ angular.module('copayApp.services')
walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
account: opts.account || 0, account: opts.account || 0,
derivationStrategy: opts.derivationStrategy || 'BIP44',
}, function(err) { }, function(err) {
if (err) { if (err) {

View File

@ -8,7 +8,7 @@ angular.module('copayApp.services')
root.callbacks = {}; root.callbacks = {};
root.getEntropySource = function(isMultisig, account, callback) { root.getEntropySource = function(isMultisig, account, callback) {
root.getXPubKey(hwWallet.getEntropyPath(isMultisig, account), function(data) { root.getXPubKey(hwWallet.getEntropyPath('trezor', isMultisig, account), function(data) {
if (!data.success) if (!data.success)
return callback(hwWallet._err(data)); return callback(hwWallet._err(data));
@ -31,13 +31,17 @@ angular.module('copayApp.services')
$log.debug('Waiting TREZOR to settle...'); $log.debug('Waiting TREZOR to settle...');
$timeout(function() { $timeout(function() {
root.getXPubKey(hwWallet.getAddressPath(isMultisig, account), function(data) { root.getXPubKey(hwWallet.getAddressPath('trezor', isMultisig, account), function(data) {
if (!data.success) if (!data.success)
return callback(hwWallet._err(data)); return callback(hwWallet._err(data));
opts.extendedPublicKey = data.xpubkey; opts.extendedPublicKey = data.xpubkey;
opts.externalSource = 'trezor'; opts.externalSource = 'trezor';
opts.account = account; opts.account = account;
if (isMultisig)
opts.derivationStrategy = 'BIP48';
return callback(null, opts); return callback(null, opts);
}); });
}, SETTLE_TIME); }, SETTLE_TIME);