예제 #1
0
        /// <inheritdoc />
        public async Task UpdateAsync(BlockchainSetting settings)
        {
            BlockchainSettingEntity entity = BlockchainSettingEntity.FromDomain(settings);

            string partitionKey = BlockchainSettingEntity.GetPartitionKey(settings.Type);
            string rowKey       = BlockchainSettingEntity.GetRowKey(settings.Type);
            string errorMessage = null;

            bool isUpdated = await _table.InsertOrModifyAsync(partitionKey, rowKey, () => entity, model =>
            {
                if (model.ETag != entity.ETag)
                {
                    errorMessage = $"Entity with type {model.Type} has eTag == {model.ETag}, eTag in update request is {entity.ETag}";

                    return(false);
                }

                model.Type             = entity.Type;
                model.ApiUrl           = entity.ApiUrl;
                model.HotWalletAddress = entity.HotWalletAddress;
                model.SignServiceUrl   = entity.SignServiceUrl;
                model.ETag             = entity.ETag;
                model.PartitionKey     = entity.PartitionKey;
                model.RowKey           = entity.RowKey;

                return(true);
            });

            if (!isUpdated)
            {
                throw new AlreadyUpdatedException(errorMessage);
            }
        }
        /// <inheritdoc/>
        public async Task UpdateAsync(BlockchainSetting settings)
        {
            await _blockchainSettingsService.UpdateAsync(settings);

            await _distributedCache.RemoveAsync(GetCacheKey(settings.Type));

            await _distributedCache.RemoveAsync(_settingsCacheKey);
        }
예제 #3
0
        /// <inheritdoc/>
        public async Task UpdateAsync(BlockchainSetting settings)
        {
            await ThrowOnNotValidHotWalletAddressAsync(settings.ApiUrl,
                                                       settings.Type,
                                                       settings.HotWalletAddress,
                                                       settings.SignServiceUrl);

            await _blockchainSettingsRepository.UpdateAsync(settings);
        }
예제 #4
0
 private BlockchainSettingsResponse MapToResponse(BlockchainSetting domainModel)
 {
     return(new BlockchainSettingsResponse()
     {
         ETag = domainModel.ETag,
         Type = domainModel.Type,
         HotWalletAddress = domainModel.HotWalletAddress,
         ApiUrl = domainModel.ApiUrl,
         SignServiceUrl = domainModel.SignServiceUrl
     });
 }
예제 #5
0
        /// <inheritdoc />
        public async Task CreateAsync(BlockchainSetting settings)
        {
            var existing = await GetBlockchainSettingEntity(settings.Type);

            if (existing != null)
            {
                throw new AlreadyExistsException($"Setting with type {settings.Type} is already exists");
            }

            BlockchainSettingEntity entity = BlockchainSettingEntity.FromDomain(settings);

            await _table.InsertAsync(entity);
        }
예제 #6
0
 public static BlockchainSettingEntity FromDomain(BlockchainSetting settings)
 {
     return(new BlockchainSettingEntity()
     {
         ApiUrl = settings.ApiUrl,
         HotWalletAddress = settings.HotWalletAddress,
         SignServiceUrl = settings.SignServiceUrl,
         Type = settings.Type,
         ETag = settings.ETag,
         PartitionKey = GetPartitionKey(settings.Type),
         RowKey = GetRowKey(settings.Type)
     });
 }
예제 #7
0
        public async Task <IActionResult> CreateAsync([FromBody] BlockchainSettingsCreateRequest request)
        {
            BlockchainSetting settings = MapToDomain(request);

            try
            {
                await _blockchainSettingsService.CreateAsync(settings);
            }
            catch (NotValidException e)
            {
                return(CreateContentResult(StatusCodes.Status400BadRequest, e.Message));
            }
            catch (AlreadyExistsException e)
            {
                return(CreateContentResult(StatusCodes.Status409Conflict, e.Message));
            }

            return(Ok());
        }
        public async Task <BlockchainSetting> GetAsync(string type)
        {
            var cachedBytes = await _distributedCache.GetAsync(GetCacheKey(type));

            BlockchainSetting item = null;

            if (cachedBytes != null)
            {
                item = CacheSerializer.Deserialize <BlockchainSetting>(cachedBytes);
            }
            else
            {
                item = await _blockchainSettingsService.GetAsync(type);

                await _distributedCache.SetAsync(GetCacheKey(type), CacheSerializer.Serialize(item), GetCacheOptions());
            }

            return(item);
        }
 public Task UpdateAsync(BlockchainSetting settings)
 {
     throw new NotImplementedException();
 }
        public Task CreateAsync(BlockchainSetting settings)
        {
            Settings.Add(settings);

            return(Task.FromResult(0));
        }
        protected override void Load(ContainerBuilder builder)
        {
            var healthServiceMock = new Mock <IHealthService>();

            healthServiceMock.Setup(x => x.GetHealthIssues()).Returns(new List <HealthIssue>());

            var ethClassicSetting = new BlockchainSetting()
            {
                Type             = "EthereumClassic",
                ETag             = DateTime.UtcNow.ToString(),
                HotWalletAddress = "0x5ADBF411FAF2595698D80B7f93D570Dd16d7F4B2",
                SignServiceUrl   = "http://ethereum-classic-sign.lykke-service.com",
                ApiUrl           = "http://ethereum-classic-api.lykke-service.com"
            };
            var listSettings = new List <BlockchainSetting>()
            {
                ethClassicSetting
            };

            #region BlockchainSettingsService

            var blockchainValidationService = new Mock <IBlockchainValidationService>();
            blockchainValidationService.Setup(x =>
                                              x.ValidateHotwalletAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult(true));
            blockchainValidationService.Setup(x =>
                                              x.ValidateServiceUrlAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(true));
            var blockchainSettingsRepository = new BlockchainSettingRepositoryFake(listSettings);
            var blockchainSettingsService    = new BlockchainSettingsService(blockchainSettingsRepository,
                                                                             blockchainValidationService.Object);
            var accessTokenService = new Mock <IAccessTokenService>();
            accessTokenService.Setup(x => x.GetTokenAccess(It.Is <string>(y => y == BlockchainSettingsTest.ReadKey)))
            .Returns(ApiKeyAccessType.Read);
            accessTokenService.Setup(x => x.GetTokenAccess(It.Is <string>(y => y == BlockchainSettingsTest.WriteKey)))
            .Returns(ApiKeyAccessType.Write);
            accessTokenService.Setup(x => x.GetTokenAccess(It.Is <string>(y => y == BlockchainSettingsTest.ReadWriteKey)))
            .Returns(ApiKeyAccessType.ReadWrite);

            builder.RegisterInstance(healthServiceMock.Object).As <IHealthService>().SingleInstance();
            BlockchainSettingsServiceCached cachedService = new BlockchainSettingsServiceCached(
                blockchainSettingsService,
                new DistributedCacheFake()
                );

            builder.RegisterInstance(accessTokenService.Object);
            builder.RegisterInstance <IBlockchainSettingsServiceCached>(cachedService).SingleInstance();

            #endregion

            #region BlockchainSettingsService

            _blockchainExplorersRepository = new BlockchainExplorersRepositoryFake(null);
            ReInitBlockchainRepository();
            var blockchainExplorersService = new BlockchainExplorersService(_blockchainExplorersRepository);


            BlockchainExplorersServiceCached cachedExplorersService = new BlockchainExplorersServiceCached(
                blockchainExplorersService,
                new DistributedCacheFake()
                );

            builder.RegisterInstance <IBlockchainExplorersServiceCached>(cachedExplorersService).SingleInstance();

            #endregion
        }