Esempio n. 1
0
        public async Task ConfigurePoolsAsync()
        {
            foreach (var config in poolConfigs)
            {
                try
                {
                    // Path for bundled genesis txn
                    var filename = Path.Combine(FileSystem.CacheDirectory, "genesis.txn");

                    // Dump file contents to cached filename
                    using (var stream = await FileSystem.OpenAppPackageFileAsync(config.Value))
                        using (var reader = new StreamReader(stream))
                        {
                            File.WriteAllText(filename, await reader.ReadToEndAsync()
                                              .ConfigureAwait(false));
                        }

                    // Create pool configuration
                    await poolService.CreatePoolAsync(config.Key, filename)
                    .ConfigureAwait(false);
                }
                catch (PoolLedgerConfigExistsException)
                {
                    // OK
                }
                catch (Exception e)
                {
                    logger.LogCritical(e, "Couldn't create pool config");
                    //throw;
                }
            }
        }
        public async Task InitializeAsync()
        {
            try
            {
                await Wallet.CreateWalletAsync(IssuerConfig, Credentials);
            }
            catch (WalletExistsException)
            {
                // OK
            }

            try
            {
                await Wallet.CreateWalletAsync(HolderConfig, Credentials);
            }
            catch (WalletExistsException)
            {
                // OK
            }

            _issuerWallet = await Wallet.OpenWalletAsync(IssuerConfig, Credentials);

            _holderWallet = await Wallet.OpenWalletAsync(HolderConfig, Credentials);

            try
            {
                await _poolService.CreatePoolAsync(PoolName, Path.GetFullPath("pool_genesis.txn"), 2);
            }
            catch (PoolLedgerConfigExistsException)
            {
                // OK
            }
            _pool = await _poolService.GetPoolAsync(PoolName, 2);
        }
Esempio n. 3
0
        /// <inheritdoc />
        /// <summary>
        /// Triggered when the application host is ready to start the service.
        /// </summary>
        /// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            try
            {
                if (_poolOptions.GenesisFilename != null)
                {
                    await _poolService.CreatePoolAsync(_poolOptions.PoolName, _poolOptions.GenesisFilename);
                }
            }
            catch (PoolLedgerConfigExistsException)
            {
                // Pool already exists, swallow exception
            }

            try
            {
                await _provisioningService.ProvisionAgentAsync(ProvisioningConfiguration);
            }
            catch (WalletExistsException)
            {
                // Wallet already exists, swallow exception
            }
            catch (AgentFrameworkException ex) when(ex.ErrorCode == ErrorCode.WalletAlreadyProvisioned)
            {
                // Wallet already provisioned
            }
            catch (WalletStorageException)
            {
                // Aggregate exception thrown when using custom wallets

                // TODO: TM: add support to Indy SDK to expose exception types
            }
        }
Esempio n. 4
0
        public static async Task <Pool> GetPoolAsync()
        {
            if (pool != null)
            {
                return(pool);
            }

            try
            {
                await poolService.CreatePoolAsync("LocalTestPool", Path.GetFullPath("pool_genesis.txn"));
            }
            catch (PoolLedgerConfigExistsException)
            {
                // OK
            }
            return(pool = await poolService.GetPoolAsync("LocalTestPool", 2));
        }
        internal async Task Build(Uri endpointUri)
        {
            try
            {
                if (_poolOptions.GenesisFilename != null)
                {
                    await _poolService.CreatePoolAsync(_poolOptions.PoolName, _poolOptions.GenesisFilename);
                }
            }
            catch (PoolLedgerConfigExistsException)
            {
                // Pool already exists, swallow exception
            }

            try
            {
                await _provisioningService.ProvisionAgentAsync(
                    new ProvisioningConfiguration
                {
                    AgentSeed           = _agentSeed,
                    EndpointUri         = endpointUri,
                    CreateIssuer        = _createIssuer,
                    IssuerSeed          = _issuerSeed,
                    OwnerName           = _agentOwnerName,
                    OwnerImageUrl       = _agentOwnerImageUrl,
                    TailsBaseUri        = TailsBaseUri ?? new Uri(endpointUri, "tails"),
                    WalletConfiguration = _walletOptions.WalletConfiguration,
                    WalletCredentials   = _walletOptions.WalletCredentials
                });
            }
            catch (WalletExistsException)
            {
                // Wallet already exists, swallow exception
            }
            catch (AgentFrameworkException ex) when(ex.ErrorCode == ErrorCode.WalletAlreadyProvisioned)
            {
                // Wallet already provisioned
            }
            catch (WalletStorageException)
            {
                // Aggregate exception thrown when using custom wallets

                // TODO: TM: add support to Indy SDK to expose exception types
            }
        }
Esempio n. 6
0
        internal async Task Build(Uri endpointUri)
        {
            try
            {
                await _walletService.CreateWalletAsync(_walletOptions.WalletConfiguration,
                                                       _walletOptions.WalletCredentials);
            }
            catch (WalletExistsException)
            {
                // Wallet already exists, swallow exception
            }

            try
            {
                await _poolService.CreatePoolAsync(_poolOptions.PoolName, _poolOptions.GenesisFilename,
                                                   _poolOptions.ProtocolVersion);
            }
            catch (PoolLedgerConfigExistsException)
            {
                // Pool already exists, swallow exception
            }

            var wallet = await _walletService.GetWalletAsync(
                _walletOptions.WalletConfiguration,
                _walletOptions.WalletCredentials);

            try
            {
                await _provisioningService.ProvisionAgentAsync(wallet, new ProvisioningConfiguration
                {
                    AgentSeed     = _agentSeed,
                    EndpointUri   = endpointUri,
                    CreateIssuer  = _createIssuer,
                    IssuerSeed    = _issuerSeed,
                    OwnerName     = _agentOwnerName,
                    OwnerImageUrl = _agentOwnerImageUrl,
                    TailsBaseUri  = TailsBaseUri ?? new Uri(endpointUri, "tails")
                });
            }
            catch (WalletAlreadyProvisionedException)
            {
                // Wallet already provisioned
            }
        }
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     try
     {
         if (_poolOptions.GenesisFilename != null)
         {
             await _poolService.CreatePoolAsync(_poolOptions.PoolName, _poolOptions.GenesisFilename);
         }
     }
     catch (PoolLedgerConfigExistsException)
     {
         // Pool already exists, swallow exception
     }
     catch (Exception e)
     {
         _logger.LogCritical(e, "Couldn't create ledger configuration");
         throw;
     }
 }
Esempio n. 8
0
 /// <inheritdoc />
 public async Task StartAsync(CancellationToken cancellationToken)
 {
     try
     {
         if (_agentOptions.GenesisFilename == null)
         {
             _logger.LogWarning("Pool configuration genesis file not supplied.");
             return;
         }
         await _poolService.CreatePoolAsync(_agentOptions.PoolName, _agentOptions.GenesisFilename);
     }
     catch (PoolLedgerConfigExistsException)
     {
         // Pool already exists, swallow exception
     }
     catch (Exception e)
     {
         _logger.LogCritical(e, "Couldn't create ledger configuration");
         throw;
     }
 }
Esempio n. 9
0
        public async Task ConfigurePoolsAsync()
        {
            foreach (var config in poolConfigs)
            {
                try
                {
                    // Path for bundled genesis txn
                    var cache    = FileSystem.CacheDirectory;
                    var filename = Path.Combine(cache, "genesis.txn");

                    // Dump file contents to cached filename
                    using (var stream = await FileSystem.OpenAppPackageFileAsync(config.Value))
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            var contents = await reader.ReadToEndAsync().ConfigureAwait(false);

                            File.WriteAllText(filename, contents);
                        }
                    }

                    // Create pool configuration
                    await poolService.CreatePoolAsync(config.Key, filename)
                    .ConfigureAwait(false);
                }
                catch (PoolLedgerConfigExistsException ex)
                {
                    // OK
                    Tracking.TrackException(ex, "Pool already exists");
                }
                catch (Exception ex)
                {
                    Tracking.TrackException(ex, "Couldn't create pool");
                }
            }
        }