Exemple #1
0
        public async Task SetApprovedAsync(string customerId, string publicAddress, string signature, Money18 fee, TransactionContext txContext = null)
        {
            using (var context = _contextFactory.CreateDataContext(txContext))
            {
                var entity = new WalletLinkingRequestEntity {
                    CustomerId = customerId
                };

                context.LinkingRequests.Attach(entity);

                entity.PublicAddress = publicAddress;
                entity.Signature     = signature;
                entity.Timestamp     = DateTime.UtcNow;
                entity.Fee           = fee;

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    _log.Error(e, EntityNotFoundWhenApproving);

                    throw new InvalidOperationException(EntityNotFoundWhenApproving);
                }
            }
        }
Exemple #2
0
        public async Task SetPubliclyConfirmedAsync(string customerId, TransactionContext txContext = null)
        {
            using (var context = _contextFactory.CreateDataContext(txContext))
            {
                var entity = new WalletLinkingRequestEntity {
                    CustomerId = customerId
                };

                context.LinkingRequests.Attach(entity);

                entity.IsConfirmedInPublic = true;
                entity.Timestamp           = DateTime.UtcNow;

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    _log.Error(e, EntityNotFoundWhenConfirming);

                    throw new InvalidOperationException(EntityNotFoundWhenConfirming);
                }
            }
        }
Exemple #3
0
        public async Task DeleteByIdAsync(string customerId, TransactionContext txContext = null)
        {
            using (var context = _contextFactory.CreateDataContext(txContext))
            {
                var entity = new WalletLinkingRequestEntity {
                    CustomerId = customerId
                };

                context.LinkingRequests.Attach(entity);

                context.LinkingRequests.Remove(entity);

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    _log.Error(e, CannotDeleteLinkingRequest);

                    throw new InvalidOperationException(CannotDeleteLinkingRequest);
                }
            }
        }
Exemple #4
0
        public async Task AddAsync(string customerId, string privateAddress, string linkCode, TransactionContext txContext = null)
        {
            using (var context = _contextFactory.CreateDataContext(txContext))
            {
                var entity = WalletLinkingRequestEntity.Create(customerId, privateAddress, linkCode);

                await context.LinkingRequests.AddAsync(entity);

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    if (e.InnerException is PostgresException sqlException &&
                        sqlException.SqlState == PostgresErrorCodes.UniqueViolation)
                    {
                        throw new LinkingRequestAlreadyExistsException(customerId);
                    }

                    throw;
                }
            }
        }