コード例 #1
0
        public async Task UpdateBitGoWallet(BitGoWallet wallet)
        {
            using var action = MyTelemetry.StartActivity("Update BitGo wallet");
            wallet.ApiKey    = _encryptionService.Encrypt(wallet.ApiKey);
            try
            {
                _logger.LogInformation("Update BitGoWallet: {jsonText}",
                                       JsonConvert.SerializeObject(wallet, new ApiKeyHiddenJsonConverter(typeof(BitGoWallet))));

                wallet.UpdatedDate = DateTime.Now;
                ValidateWallet(wallet);

                var entity = BitGoWalletNoSqlEntity.Create(wallet);

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

                if (existingItem == null)
                {
                    throw new Exception("Cannot update BitGo wallet. Do not exist");
                }

                await _writer.InsertOrReplaceAsync(entity);

                _logger.LogInformation("Updated BitGo wallet: {jsonText}",
                                       JsonConvert.SerializeObject(wallet, new ApiKeyHiddenJsonConverter(typeof(BitGoWallet))));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Cannot update BitGo wallet: {requestJson}",
                                 JsonConvert.SerializeObject(wallet, new ApiKeyHiddenJsonConverter(typeof(BitGoWallet))));
                ex.FailActivity();
                throw;
            }
        }
コード例 #2
0
 public static BitGoWalletNoSqlEntity Create(BitGoWallet wallet)
 {
     return(new BitGoWalletNoSqlEntity
     {
         PartitionKey = GeneratePartitionKey(wallet.BrokerId),
         RowKey = GenerateRowKey(wallet.Id),
         Wallet = wallet
     });
 }
コード例 #3
0
 private static void ValidateWallet(BitGoWallet wallet)
 {
     if (string.IsNullOrEmpty(wallet.BrokerId))
     {
         throw new Exception("Cannot add wallet with empty broker");
     }
     if (string.IsNullOrEmpty(wallet.Id))
     {
         throw new Exception("Cannot add wallet with empty id");
     }
     if (string.IsNullOrEmpty(wallet.CoinId))
     {
         throw new Exception("Cannot add wallet with coin id");
     }
 }