예제 #1
0
        public async Task HandleAsync()
        {
            var keysGroup = notice.Keys.GroupBy(opt => opt.UserId);

            foreach (var group in keysGroup)
            {
                var keys = await keysService.AddNewUserKeysAsync(notice.Keys, notice.UserId).ConfigureAwait(false);

                BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateNewUserKeysSegmentAsync(keys.ToList(), group.Key.GetValueOrDefault(), current.Node.Id).ConfigureAwait(false);

                BlockGenerationHelper.Instance.AddSegment(segment);
            }
        }
예제 #2
0
        public async Task <Response> CreateResponseAsync()
        {
            try
            {
                foreach (var key in request.Keys)
                {
                    key.UserId = clientConnection.UserId.GetValueOrDefault();
                }
                List <KeyVm> keys =
                    await keysService.AddNewUserKeysAsync(request.Keys, clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false);

                BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateNewUserKeysSegmentAsync(
                    keys.ToList(),
                    clientConnection.UserId.GetValueOrDefault(),
                    NodeSettings.Configs.Node.Id).ConfigureAwait(false);

                BlockGenerationHelper.Instance.AddSegment(segment);
                nodeNoticeService.SendNewKeysBlockNoticeAsync(keys.ToList(), clientConnection.UserId.GetValueOrDefault());
                return(new KeysResponse(request.RequestId, keys));
            }
            catch (ObjectAlreadyExistsException)
            {
                var errorObject = new
                {
                    Key = "Key with the specified identifier already exists"
                };
                return(new ResultResponse(request.RequestId, errorObject.ToJson(), ObjectsLibrary.Enums.ErrorCode.WrongArgumentError));
            }
            catch (KeyTimeoutException)
            {
                return(new ResultResponse(request.RequestId, "Key timeout.", ObjectsLibrary.Enums.ErrorCode.KeyTimeout));
            }
            catch (InvalidSignException)
            {
                return(new ResultResponse(request.RequestId, "Invalid sign.", ObjectsLibrary.Enums.ErrorCode.InvalidSign));
            }
        }