public async Task AddBitGoWallet(BitGoWallet wallet)
        {
            using var action = MyTelemetry.StartActivity("Add BitGo wallet");
            wallet.ApiKey    = _encryptionService.Encrypt(wallet.ApiKey);
            try
            {
                _logger.LogInformation("Add BitGoWallet: {jsonText}",
                                       JsonConvert.SerializeObject(wallet, new ApiKeyHiddenJsonConverter(typeof(BitGoWallet))));

                ValidateWallet(wallet);

                var entity = BitGoWalletNoSqlEntity.Create(wallet);

                var existingItem = await _writer.GetAsync(entity.PartitionKey, entity.RowKey);

                if (existingItem != null)
                {
                    throw new Exception("Cannot add BitGo wallet. Already exist");
                }

                await _writer.InsertAsync(entity);

                _logger.LogInformation("Added BitGo wallet: {jsonText}",
                                       JsonConvert.SerializeObject(wallet, new ApiKeyHiddenJsonConverter(typeof(BitGoWallet))));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Cannot add BitGo wallet: {requestJson}",
                                 JsonConvert.SerializeObject(wallet, new ApiKeyHiddenJsonConverter(typeof(BitGoWallet))));
                ex.FailActivity();
                throw;
            }
        }
Пример #2
0
        public async Task AddSpotInstrumentFeesSettings(SpotInstrumentFees settings)
        {
            using var action = MyTelemetry.StartActivity("Add Spot Instrument Fees Settings");
            settings.AddToActivityAsJsonTag("settings");
            try
            {
                _logger.LogInformation("Add Spot Instrument Fees Setting: {jsonText}",
                                       JsonConvert.SerializeObject(settings));

                ValidateSettings(settings);

                var entity = SpotInstrumentFeesNoSqlEntity.Create(settings);

                var existingItem = await _writer.GetAsync(entity.PartitionKey, entity.RowKey);

                if (existingItem != null)
                {
                    throw new Exception("Cannot add Spot Instrument Fees Settings. Already exist");
                }

                await _writer.InsertAsync(entity);

                _logger.LogInformation("Added Spot Instrument Fees Setting: {jsonText}",
                                       JsonConvert.SerializeObject(settings));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Cannot add ExternalMarketSettings: {requestJson}",
                                 JsonConvert.SerializeObject(settings));
                ex.FailActivity();
                throw;
            }
        }
        public async ValueTask <bool> CreateBitgoCoinEntityAsync(string coin, int accuracy, int requiredConfirmations, bool isMainNet)
        {
            if (string.IsNullOrEmpty(coin))
            {
                throw new Exception("Cannot create coin. Coin cannot be empty");
            }
            if (accuracy < 0)
            {
                throw new Exception("Cannot create coin. Accuracy can't be less then 0");
            }
            if (requiredConfirmations < 0)
            {
                throw new Exception("Cannot create coin. RequiredConfirmations can't be less then 0");
            }

            var entity = BitgoCoinEntity.Create(coin, accuracy, requiredConfirmations, isMainNet);

            var existingItem = await _bitgoCoins.GetAsync(entity.PartitionKey, entity.RowKey);

            if (existingItem != null)
            {
                throw new Exception("Cannot create coin. Already exist");
            }

            await _bitgoCoins.InsertAsync(entity);

            return(true);
        }
Пример #4
0
        public async Task CreateDefaultTemplatesAsync()
        {
            var templateEntities = (await _templateWriter.GetAsync())?.ToArray();
            var templateIds      = Enum.GetValues(typeof(TemplateEnum)).Cast <TemplateEnum>();

            foreach (var templateId in templateIds)
            {
                var template = templateEntities?.FirstOrDefault(e => e.Template.Id == templateId)?.Template;
                if (template == null)
                {
                    template = new SmsTemplate
                    {
                        Id              = templateId,
                        DefaultLang     = _defaultLang,
                        DefaultBrand    = _defaultBrand,
                        BrandLangBodies = GetTemplateLangBodies(templateId),
                        Params          = GetTemplateBodyParams(templateId)
                    };

                    var newTemplateEntity = TemplateMyNoSqlEntity.Create(template);
                    await _templateWriter.InsertAsync(newTemplateEntity);

                    _logger.LogInformation("Template (ID: {templateId}) doesn't exist, creating the new one.", templateId);
                }
            }
        }
        public async Task <ClientIdentity> RegisterClientAsync(
            string tenantId,
            string requestEmail,
            string requestPhone,
            string requestFullName,
            string requestCountryIso3Code,
            string requestAffiliateCode)
        {
            var iteration = 0;
            PersonalDataEntity entity;

            while (true)
            {
                iteration++;

                try
                {
                    var clientId = (long)(DateTime.UtcNow - DateTime.Parse("2020-01-01")).TotalSeconds;

                    entity                      = PersonalDataEntity.Generate(tenantId, clientId);
                    entity.Data.Email           = requestEmail;
                    entity.Data.FullName        = requestFullName;
                    entity.Data.Phone           = requestPhone;
                    entity.Data.AffiliateCode   = requestAffiliateCode;
                    entity.Data.CountryIso3Code = requestCountryIso3Code;

                    await _dataWriter.InsertAsync(entity);

                    break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"ERROR in PersonalDataMock.RegisterClientAsync. Iteration: {iteration}");
                    Console.WriteLine(ex);

                    if (iteration > 10)
                    {
                        throw;
                    }
                }
            }

            return(new ClientIdentity()
            {
                ClientId = entity.Data.ClientId,
                TenantId = entity.Data.TenantId
            });
        }
Пример #6
0
        public static async Task <bool> TryInsertAsync <TEntity>(this IMyNoSqlServerDataWriter <TEntity> writer, TEntity entity) where TEntity : IMyNoSqlDbEntity, new()
        {
            try
            {
                await writer.InsertAsync(entity);

                return(true);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("Call failed with status code 409 (Conflict)"))
                {
                    return(false);
                }

                throw;
            }
        }
Пример #7
0
        public async ValueTask <bool> CreateBitgoAssetMapEntityAsync(string brokerId, string assetSymbol,
                                                                     string bitgoWalletId, string enabledBitgoWalletIds, string bitgoCoin, double minBalance, string tagSeparator)
        {
            if (string.IsNullOrEmpty(brokerId))
            {
                throw new Exception("Cannot create asset map. BrokerId cannot be empty");
            }
            if (string.IsNullOrEmpty(assetSymbol))
            {
                throw new Exception("Cannot create asset map. AssetSymbol cannot be empty");
            }
            if (string.IsNullOrEmpty(bitgoWalletId))
            {
                throw new Exception("Cannot create asset map. BitgoWalletId cannot be empty");
            }
            if (string.IsNullOrEmpty(bitgoCoin))
            {
                throw new Exception("Cannot create asset map. BitgoCoin cannot be empty");
            }

            var coin = await _bitgoCoins.GetAsync(BitgoCoinEntity.GeneratePartitionKey(),
                                                  BitgoCoinEntity.GenerateRowKey(bitgoCoin));

            if (coin == null)
            {
                throw new Exception("Cannot create asset map. Unknown BitgoCoin.");
            }

            var entity =
                BitgoAssetMapEntity.Create(brokerId, assetSymbol, bitgoWalletId, enabledBitgoWalletIds, bitgoCoin, minBalance, tagSeparator);

            var existingItem = await _assetMap.GetAsync(entity.PartitionKey, entity.RowKey);

            if (existingItem != null)
            {
                throw new Exception("Cannot create asset map. Already exist");
            }

            await _assetMap.InsertAsync(entity);

            return(true);
        }
        private async Task DoTime()
        {
            var maxCount = Program.ReloadedSettings(e => e.PreGeneratedAddressesCount).Invoke();
            var wallets  = await _bitGoAssetMapSettingsService.GetAllAssetMapsAsync();

            foreach (var wallet in wallets)
            {
                var assetIdentity = new AssetIdentity
                {
                    BrokerId = wallet.BrokerId,
                    Symbol   = wallet.AssetSymbol
                };

                var paymentSettings = _assetPaymentSettingsClient.GetAssetById(assetIdentity);
                if (paymentSettings?.BitGoCrypto?.IsEnabledDeposit != true)
                {
                    continue;
                }

                var asset = _assetsDictionaryClient.GetAssetById(assetIdentity);

                if (asset == null || !asset.IsEnabled)
                {
                    continue;
                }

                var blockchain = asset.DepositBlockchains.FirstOrDefault();
                if (string.IsNullOrEmpty(blockchain))
                {
                    continue;
                }

                var entitiesCount = await _dataWriter.GetCountAsync(
                    GeneratedDepositAddressEntity.GeneratePartitionKey(wallet.BrokerId, wallet.BitgoCoin,
                                                                       wallet.BitgoWalletId, blockchain));

                if (entitiesCount < maxCount)
                {
                    for (var i = 1; i <= maxCount - entitiesCount; i++)
                    {
                        try
                        {
                            var id    = Guid.NewGuid().ToString();
                            var label = $"PreGenerated-{id}";
                            var(addressId, address, error) =
                                await _depositAddressGeneratorService.GenerateOrGetAddressIdAsync(wallet.BitgoCoin,
                                                                                                  wallet.BitgoWalletId, label);

                            if (string.IsNullOrEmpty(addressId) || error != null)
                            {
                                _logger.LogError(
                                    "Unable to pre-generate address for broker {broker}, asset {asset}, wallet id {walletId}: {error}",
                                    wallet.BrokerId, wallet.BitgoCoin, wallet.BitgoWalletId, error);
                                continue;
                            }

                            await _dataWriter.InsertAsync(GeneratedDepositAddressEntity.Create(
                                                              new GeneratedDepositAddress
                            {
                                BrokerId             = wallet.BrokerId,
                                Asset                = wallet.BitgoCoin,
                                WalletId             = wallet.BitgoWalletId,
                                PreGeneratedWalletId = id,
                                AddressLabel         = label,
                                Address              = address,
                                BitGoAddressId       = addressId,
                                Blockchain           = blockchain
                            }));
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError(ex,
                                             "Unable to pre-generate address for broker {broker}, asset {asset}, wallet id {walletId}, blockchain {blockchain}",
                                             wallet.BrokerId, wallet.BitgoCoin, wallet.BitgoWalletId, blockchain);
                        }
                    }

                    _logger.LogInformation(
                        "Pre-generated {count} addresses for broker {broker}, asset {asset}, wallet id {walletId}, blockchain {blockchain}",
                        maxCount - entitiesCount, wallet.BrokerId, wallet.BitgoCoin, wallet.BitgoWalletId, blockchain);
                }
            }
        }