Esempio n. 1
0
        private ConsentManagementSettings CreateNewConsentManagementServiceAccount()
        {
            ConsentManagementSettings settings;
            long accountId = _accountsService.Create(AccountType.User, nameof(ConsentManagementService), GetDefaultConsentManagementPassword(), true);

            settings = new ConsentManagementSettings
            {
                AccountId = accountId
            };
            _dataAccessService.SetConsentManagementSettings(settings);
            return(settings);
        }
Esempio n. 2
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);
            });
        }