Beispiel #1
0
        public void TestNoteGenerationAndExtraction()
        {
            var withdrawalId = 101l;
            var service      = new FireblocksWithdrawalNoteService();

            var note     = service.GenerateManualNote(withdrawalId);
            var actualId = service.GetWithdrawalIdFromNote(note);

            Assert.AreEqual(withdrawalId, actualId);
        }
        public async Task <GetWithdrawalManualNoteResponse> GetWithdrawalManualNote(GetWithdrawalManualNoteRequest request)
        {
            request.AddToActivityAsJsonTag("request-data");
            _logger.LogInformation("Receive GetWithGetWithdrawalManualNotedrawal request: {JsonRequest}", JsonConvert.SerializeObject(request));

            try
            {
                await using var context = new DatabaseContext(_dbContextOptionsBuilder.Options);
                var withdrawal = await context.Withdrawals
                                 .Where(e => e.Id == request.Id)
                                 .FirstOrDefaultAsync();

                if (withdrawal == null)
                {
                    return(new GetWithdrawalManualNoteResponse()
                    {
                        Success = false,
                        ErrorMessage = $"Withdrawal with Id {request.Id} was not found"
                    });
                }

                var response = new GetWithdrawalManualNoteResponse
                {
                    Success    = true,
                    ManualNote = _fireblocksWithdrawalNoteService.GenerateManualNote(withdrawal.Id)
                };

                _logger.LogInformation("Return GetWithdrawalManualNoteResponse response for Id: {id}",
                                       withdrawal.TransactionId);
                return(response);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception,
                                 "Cannot get GetWithdrawalManualNoteResponse Id: {Id}",
                                 request.Id);
                return(new GetWithdrawalManualNoteResponse {
                    Success = false, ErrorMessage = exception.Message
                });
            }
        }