Select Git revision
revocation.rs
-
Nicolas80 authored
* Added "/.idea" exclusion in .gitignore (for when using JetBrains IDEs) * Added dialoguer dependency for easier user input handling (see in inputs.rs) * Added sea-orm dependency to allow having DB entity mappings and use a local sqlite file database * Added rstest test dependency for parameterized tests support * Added derivation tests for each SecretFormat (including cesium v1 key derivation, using sp_core::ed25519::Pair) * Made a lot of changes to add vault_account and vault_derivation db tables to persist vault keys & derivations * Added support for KeyPair::Ed25519 linking to sp_core::ed25519::Pair which can be created from secret seed retrieved from nacl::sign::Keypair (which is created from cesium id + secret) ** This was necessary to allow deriving keys from "cesium v1" keys (to be reviewed - it might be a bad idea to permit that from a security point of view) * Only kept original (substrate) keyfiles support for migration (use "vault list-files" and "vault migrate") * Added possibility to give either "-a" Address or "-v" Vault Name as general option * Added extra commands in Vault ** list-files: (deprecated)List available key files (needs to be migrated with command "vault migrate" in order to use them) ** migrate: (deprecated)Migrate old key files into db (will have to provide password for each key) ** 'list' now has sub-commands 'all' or 'root' to show all keys or only root keys (without derivation path) ** use: "Use specific vault key (changes the config address)", which will have the same behaviour as `gcli <-a <Address>|-v <VaultName>> config save` (left a FIXME in there to review) ** derivation: Add a derivation to an existing (root) vault key ** rename: Give a meaningful vault name to a vault key or derivation ** remove: Remove a vault key (and potential derivations if it's a root key) * Had to bubble up "await" and "async" in a lot of places * ...
Nicolas80 authored* Added "/.idea" exclusion in .gitignore (for when using JetBrains IDEs) * Added dialoguer dependency for easier user input handling (see in inputs.rs) * Added sea-orm dependency to allow having DB entity mappings and use a local sqlite file database * Added rstest test dependency for parameterized tests support * Added derivation tests for each SecretFormat (including cesium v1 key derivation, using sp_core::ed25519::Pair) * Made a lot of changes to add vault_account and vault_derivation db tables to persist vault keys & derivations * Added support for KeyPair::Ed25519 linking to sp_core::ed25519::Pair which can be created from secret seed retrieved from nacl::sign::Keypair (which is created from cesium id + secret) ** This was necessary to allow deriving keys from "cesium v1" keys (to be reviewed - it might be a bad idea to permit that from a security point of view) * Only kept original (substrate) keyfiles support for migration (use "vault list-files" and "vault migrate") * Added possibility to give either "-a" Address or "-v" Vault Name as general option * Added extra commands in Vault ** list-files: (deprecated)List available key files (needs to be migrated with command "vault migrate" in order to use them) ** migrate: (deprecated)Migrate old key files into db (will have to provide password for each key) ** 'list' now has sub-commands 'all' or 'root' to show all keys or only root keys (without derivation path) ** use: "Use specific vault key (changes the config address)", which will have the same behaviour as `gcli <-a <Address>|-v <VaultName>> config save` (left a FIXME in there to review) ** derivation: Add a derivation to an existing (root) vault key ** rename: Give a meaningful vault name to a vault key or derivation ** remove: Remove a vault key (and potential derivations if it's a root key) * Had to bubble up "await" and "async" in a lot of places * ...
common-controllers.js 12.65 KiB
angular.module('cesium.graph.common.controllers', ['cesium.services'])
.controller('GpCurrencyAbstractCtrl', GpCurrencyAbstractController)
;
function GpCurrencyAbstractController($scope, $filter, $ionicPopover, $ionicHistory, $state, csSettings, csCurrency, esHttp, UIUtils) {
'ngInject';
$scope.loading = true;
$scope.formData = $scope.formData || {
useRelative: csSettings.data.useRelative,
timePct: 100,
rangeDuration: 'day',
maxAge: undefined, // forever
firstBlockTime: 0,
scale: 'linear',
hide: [],
beginAtZero: true
};
$scope.scale = 'linear';
$scope.height = undefined;
$scope.width = undefined;
$scope.maintainAspectRatio = true;
$scope.times = [];
function _truncDate(time) {
return moment.unix(time).utc().startOf($scope.formData.rangeDuration).unix();
}
$scope.enter = function (e, state) {
if ($scope.loading) {
// Make sure there is currency, or load it not
if (!$scope.formData.currency) {
return csCurrency.get()
.then(function (currency) {
$scope.formData.currency = currency ? currency.name : null;
$scope.formData.firstBlockTime = currency ? _truncDate(currency.firstBlockTime) : 0;
if (!$scope.formData.firstBlockTime){
console.warn('[graph] currency.firstBlockTime not loaded ! Should have been loaded by currrency service!');
}
$scope.formData.currencyAge = _truncDate(moment().utc().unix()) - $scope.formData.firstBlockTime;
return $scope.enter(e, state); // Loop
});
}
if (state && state.stateParams) {
// remember state, to be able to refresh location
$scope.stateName = state && state.stateName;
$scope.stateParams = angular.copy(state && state.stateParams||{});
if (!$scope.formData.currency && state && state.stateParams && state.stateParams.currency) { // Currency parameter
$scope.formData.currency = state.stateParams.currency;
}
if (state.stateParams.t) {
$scope.formData.timePct = state.stateParams.t;
}
else if (state.stateParams.timePct) {
$scope.formData.timePct = state.stateParams.timePct;
}
if (state.stateParams.stepUnit) {
$scope.formData.rangeDuration = state.stateParams.stepUnit;
}
if (state.stateParams.scale) {
$scope.formData.scale = state.stateParams.scale;
}
// Allow to hide some dataset
if (state.stateParams.hide) {
$scope.formData.hide = state.stateParams.hide.split(',').reduce(function(res, index){
return res.concat(parseInt(index));
}, []);
}
}
// Should be override by subclasses
$scope.init(e, state);
$scope.load() // Should be override by subclasses
.then(function () {
// Update scale
$scope.setScale($scope.formData.scale);
// Hide some dataset by index (read from state params)
$scope.updateHiddenDataset();
$scope.loading = false;
});
}
};
$scope.$on('$csExtension.enter', $scope.enter);
$scope.$on('$ionicParentView.enter', $scope.enter);
$scope.updateLocation = function() {
if (!$scope.stateName) return;
$ionicHistory.nextViewOptions({
disableAnimate: true,
disableBack: true,
historyRoot: true
});
$scope.stateParams = $scope.stateParams || {};
$scope.stateParams.t = ($scope.formData.timePct >= 0 && $scope.formData.timePct < 100) ? $scope.formData.timePct : undefined;
$scope.stateParams.stepUnit = $scope.formData.rangeDuration !== 'day' ? $scope.formData.rangeDuration : undefined;
$scope.stateParams.hide = $scope.formData.hide && $scope.formData.hide.length ? $scope.formData.hide.join(',') : undefined;
$scope.stateParams.scale = $scope.formData.scale !== 'linear' ?$scope.formData.scale : undefined;
$state.go($scope.stateName, $scope.stateParams, {
reload: false,
inherit: true,
notify: false}
);
};
// Allow to fixe size, form a template (e.g. in a 'ng-init' tag)
$scope.setSize = function(height, width, maintainAspectRatio) {
$scope.height = height;
$scope.width = width;
$scope.maintainAspectRatio = angular.isDefined(maintainAspectRatio) ? maintainAspectRatio : $scope.maintainAspectRatio;
};
// When parent view execute a refresh action
$scope.$on('csView.action.refresh', function(event, context) {
if (!context || context === 'currency') {
return $scope.load();
}
});
$scope.init = function(e, state) {
// Should be override by subclasses
};
$scope.load = function() {
// Should be override by subclasses
};
$scope.toggleScale = function() {
$scope.setScale($scope.formData.scale === 'linear' ? 'logarithmic' : 'linear');
$scope.updateLocation();
};
$scope.setScale = function(scale) {
$scope.hideActionsPopover();
$scope.formData.scale = scale;
if (!$scope.options || !$scope.options.scales || !$scope.options.scales.yAxes) return;
var format = $filter('formatInteger');
_.forEach($scope.options.scales.yAxes, function(yAxe, index) {
yAxe.type = scale;
yAxe.ticks = yAxe.ticks || {};
if (scale === 'linear') {
yAxe.ticks.beginAtZero = angular.isDefined($scope.formData.beginAtZero) ? $scope.formData.beginAtZero : true;
delete yAxe.ticks.min;
yAxe.ticks.callback = function(value) {
return format(value);
};
}
else {
//yAxe.ticks.min = 0;
delete yAxe.ticks.beginAtZero;
delete yAxe.ticks.callback;
yAxe.ticks.callback = function(value, index) {
if (!value) return;
if (Math.log10(value)%1 === 0 || Math.log10(value/3)%1 === 0) {
return format(value);
}
return '';
};
}
});
};
$scope.setRangeDuration = function(rangeDuration) {
$scope.hideActionsPopover();
if ($scope.formData && rangeDuration === $scope.formData.rangeDuration) return;
$scope.formData.rangeDuration = rangeDuration;
// Restore default values
delete $scope.formData.startTime;
delete $scope.formData.endTime;
delete $scope.formData.rangeDurationSec;
//$scope.formData.timePct = 100;
// Reload data
$scope.load();
// Update location
$scope.updateLocation();
};
$scope.setMaxAge = function(maxAge) {
$scope.hideActionsPopover();
if ($scope.formData && maxAge === $scope.formData.maxAge) return;
$scope.formData.maxAge = maxAge;
// Restore default values
delete $scope.formData.startTime;
delete $scope.formData.endTime;
delete $scope.formData.rangeDurationSec;
$scope.computeStartTimeByAge(); // Compute formData.startTime
// Reload data
$scope.load();
// Update location
$scope.updateLocation();
};
$scope.computeStartTimeByAge = function() {
if (!$scope.formData.maxAge) {
delete $scope.formData.startTime; // Forever
}
else {
var ageInSecond = 60 * 60; // one hour
switch ($scope.formData.maxAge) {
case 'day':
ageInSecond *= 24;
break;
case 'week':
ageInSecond *= 24 * 7;
break;
case 'month':
ageInSecond *= 24 * 365.25/12;
break;
case 'quarter':
ageInSecond *= 24 * 365.25/4;
break;
case 'semester':
ageInSecond *= 24 * 365.25/2;
break;
case 'year':
ageInSecond *= 24 * 365.25;
break;
}
$scope.formData.startTime = moment.utc().unix() - ageInSecond;
}
};
$scope.updateHiddenDataset = function(datasetOverride) {
datasetOverride = datasetOverride || $scope.datasetOverride || {};
_.forEach($scope.formData.hide||[], function(index) {
if (!datasetOverride[index]) return; // skip invalid index
// Hide the dataset (stroke the legend)
datasetOverride[index].hidden = true;
// If this dataset has an yAxis, hide it (if not used elsewhere)
var yAxisID = datasetOverride[index].yAxisID;
var yAxe = yAxisID && $scope.options && $scope.options.scales && _.findWhere($scope.options.scales.yAxes||[], {id: yAxisID});
if (yAxisID && yAxe) {
var yAxisDatasetCount = _.filter(datasetOverride, function(dataset) {
return dataset.yAxisID === yAxisID;
}).length;
if (yAxisDatasetCount === 1) {
yAxe.display = false;
}
}
});
};
$scope.onLegendClick = function(e, legendItem) {
var index = legendItem.datasetIndex;
var ci = this.chart;
var meta = ci.getDatasetMeta(index);
// Hide/show the dataset
meta.hidden = meta.hidden === null? !ci.data.datasets[index].hidden : null;
// Update yAxis display (if used by only ONE dataset)
if (ci.config && ci.config.data && ci.config.data.datasets) {
var yAxisDatasetCount = _.filter(ci.config.data.datasets, function(dataset) {
return dataset.yAxisID && dataset.yAxisID === meta.yAxisID;
}).length;
if (yAxisDatasetCount === 1) {
ci.scales[meta.yAxisID].options.display = (meta.hidden !== false);
}
}
// We hid a dataset ... rerender the chart
ci.update();
// Update window location
$scope.formData.hide = $scope.formData.hide||[];
$scope.formData.hide = meta.hidden ?
_.union($scope.formData.hide, [index]) :
_.difference($scope.formData.hide, [index]);
$scope.updateLocation();
};
$scope.goPreviousRange = function() {
if ($scope.loadingRange) return;
$scope.loadingRange = true;
$scope.formData.startTime -= $scope.times.length * $scope.formData.rangeDurationSec;
if ($scope.formData.startTime < $scope.formData.firstBlockTime) {
$scope.formData.startTime = $scope.formData.firstBlockTime;
}
$scope.formData.endTime = $scope.formData.startTime + $scope.times.length * $scope.formData.rangeDurationSec;
// Reload data
$scope.load().then(function(){
// Update location
$scope.updateLocation();
$scope.loadingRange = false;
});
};
$scope.goNextRange = function() {
if ($scope.loadingRange) return;
$scope.loadingRange = true;
$scope.formData.startTime += $scope.times.length * $scope.formData.rangeDurationSec;
if ($scope.formData.startTime > $scope.formData.firstBlockTime + $scope.formData.currencyAge - $scope.formData.timeWindow) {
$scope.formData.startTime = $scope.formData.firstBlockTime + $scope.formData.currencyAge - $scope.formData.timeWindow;
}
$scope.formData.endTime = $scope.formData.startTime + $scope.times.length * $scope.formData.rangeDurationSec;
// Reload data
$scope.load().then(function(){
// Update location
$scope.updateLocation();
$scope.loadingRange = false;
});
};
$scope.onRangeChanged = function() {
if ($scope.loadingRange) return;
$scope.loadingRange = true;
$scope.formData.startTime = $scope.formData.firstBlockTime + (parseFloat($scope.formData.timePct) / 100) * ($scope.formData.currencyAge - $scope.formData.timeWindow) ;
$scope.formData.endTime = $scope.formData.startTime + $scope.times.length * $scope.formData.rangeDurationSec;
// Reload data
$scope.load().then(function(){
// Update location
$scope.updateLocation();
$scope.loadingRange = false;
});
};
$scope.updateRange = function(startTime, endTime, updateTimePct) {
updateTimePct = angular.isDefined(updateTimePct) ? updateTimePct : true;
$scope.formData.startTime = startTime;
$scope.formData.endTime = endTime;
$scope.formData.timeWindow = $scope.formData.timeWindow || $scope.formData.endTime - $scope.formData.startTime;
$scope.formData.rangeDurationSec = $scope.formData.rangeDurationSec || $scope.formData.timeWindow / ($scope.times.length-1);
if (updateTimePct) {
$scope.formData.timePct = Math.ceil(($scope.formData.startTime - $scope.formData.firstBlockTime) * 100 /
($scope.formData.currencyAge - $scope.formData.timeWindow));
}
};
/* -- Popover -- */
$scope.showActionsPopover = function(event, options) {
var templateUrl = options && options.templateUrl || 'plugins/graph/templates/common/popover_range_actions.html';
UIUtils.popover.show(event, {
templateUrl: templateUrl,
scope: $scope,
autoremove: true,
afterShow: function(popover) {
$scope.actionsPopover = popover;
}
});
};
$scope.showPeriodPopover = function(event) {
return $scope.showActionsPopover(event, {templateUrl: 'plugins/graph/templates/common/popover_period_actions.html'});
};
$scope.hideActionsPopover = function() {
if ($scope.actionsPopover) {
$scope.actionsPopover.hide();
$scope.actionsPopover = null;
}
};
}