public IActionResult RemoveAccount([FromBody] AccountDto account)
        {
            if (account != null)
            {
                _accountsService.Delete(account.AccountId);
                _executionContextManager.UnregisterExecutionServices(account.AccountId);
                return(Ok());
            }

            return(BadRequest());
        }
Exemple #2
0
        public ScenarioSession AbandonScenario(string userSubject, int id)
        {
            _logger.Info($"{nameof(AbandonScenario)}({userSubject}, {id})");
            try
            {
                ScenarioDefinition scenarioDefinition = _scenarios[id];
                ScenarioSession    scenarioSession    = _dataAccessService.GetScenarioSessions(userSubject).FirstOrDefault(s => s.ScenarioId == id);

                if (scenarioSession == null)
                {
                    return(null);
                }

                IEnumerable <Client.DataLayer.Model.Scenarios.ScenarioAccount> scenarioAccounts = _dataAccessService.GetScenarioAccounts(scenarioSession.ScenarioSessionId);

                foreach (var scenarioAccount in scenarioAccounts)
                {
                    _executionContextManager.UnregisterExecutionServices(scenarioAccount.AccountId);
                }

                _activeScenarios.TryRemove(userSubject, out ScenarioMonitoringData scenarioMonitoringData);

                return(scenarioSession);
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed {nameof(AbandonScenario)}({userSubject}, {id})", ex);
                throw;
            }
        }
        public void Initialize(CancellationToken cancellationToken)
        {
            _logger.Info($"Initializing {nameof(O10InherenceService)}");

            InherenceSetting inherenceSetting = _dataAccessService.GetInherenceSetting(Name);

            if (inherenceSetting == null)
            {
                inherenceSetting = CreateO10Inherence();
            }

            AccountId = inherenceSetting.AccountId;
            _logger.LogIfDebug(() => $"[{AccountId}]: {nameof(Initialize)} proceeding");


            AccountDescriptor accountDescriptor = _accountsService.GetById(inherenceSetting.AccountId);

            if (accountDescriptor == null)
            {
                _dataAccessService.RemoveInherenceSetting(Name);
                inherenceSetting  = CreateO10Inherence();
                accountDescriptor = _accountsService.Authenticate(inherenceSetting.AccountId, GetDefaultO10InherencePassword());
                if (accountDescriptor == null)
                {
                    throw new Exception($"{nameof(O10InherenceService)} initialization failed");
                }
            }
            else
            {
                accountDescriptor = _accountsService.Authenticate(inherenceSetting.AccountId, GetDefaultO10InherencePassword());
            }

            _logger.Info($"[{AccountId}]: Invoking InitializeStateExecutionServices");
            _executionContextManager
            .InitializeStateExecutionServices(
                accountDescriptor.AccountId,
                accountDescriptor.SecretSpendKey,
                new Func <long, IStateTransactionsService, IStateClientCryptoService, CancellationToken, IUpdater>(
                    (accountId, stateTransactionsService, stateClientSryptoService, ct) =>
            {
                _clientCryptoService = stateClientSryptoService;
                return(this);
            }));

            Target = accountDescriptor.PublicSpendKey.ToHexString();

            cancellationToken.Register(() =>
            {
                _executionContextManager.UnregisterExecutionServices(AccountId);
            });
        }
Exemple #4
0
        public void Initialize(IExecutionContextManager executionContextManager, CancellationToken cancellationToken)
        {
            _executionContextManager = executionContextManager;
            ConsentManagementSettings settings = _dataAccessService.GetConsentManagementSettings();

            if (settings == null)
            {
                settings = CreateNewConsentManagementServiceAccount();
            }

            AccountDescriptor accountDescriptor = _accountsService.Authenticate(settings.AccountId, GetDefaultConsentManagementPassword());

            if (accountDescriptor == null)
            {
                settings          = CreateNewConsentManagementServiceAccount();
                accountDescriptor = _accountsService.Authenticate(settings.AccountId, GetDefaultConsentManagementPassword());
                if (accountDescriptor == null)
                {
                    throw new Exception("ConsentManagementService initialization failed");
                }
            }

            _accountId = accountDescriptor.AccountId;

            _executionContextManager
            .InitializeUtxoExecutionServices(
                accountDescriptor.AccountId,
                accountDescriptor.SecretSpendKey,
                accountDescriptor.SecretViewKey,
                accountDescriptor.PwdHash,
                new Func <long, IUtxoClientCryptoService, CancellationToken, IUpdater>(
                    (accountId, clientCryptoService, ct) =>
            {
                _clientCryptoService = clientCryptoService;
                return(this);
            }));

            PublicSpendKey = accountDescriptor.PublicSpendKey.ToHexString();
            PublicViewKey  = accountDescriptor.PublicViewKey.ToHexString();

            cancellationToken.Register(() =>
            {
                _executionContextManager.UnregisterExecutionServices(_accountId);
            });
        }
Exemple #5
0
        public IActionResult SetPollState(long pollId, [FromBody] SetPollStateRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var poll      = _electionCommitteeService.SetPollState(pollId, request.State);
            var pollModel = _dataAccessService.GetEcPoll(pollId);
            var account   = _dataAccessService.GetAccount(pollModel.AccountId);

            if (poll.State == PollState.Started)
            {
                _executionContextManager.InitializeStateExecutionServices(account.AccountId, account.SecretSpendKey);
                _electionCommitteeService.IssueVotersRegistrations(pollId, request.SourceAccountId);
            }
            else
            {
                _executionContextManager.UnregisterExecutionServices(pollModel.AccountId);
            }


            return(Ok(poll));
        }