public async Task Consume(ConsumeContext <WalletGenerationRequestUpdated> context)
        {
            var @event = context.Message;

            var blockchain = await _blockchainsRepository.GetByIdAsync(@event.BlockchainId);

            if (blockchain == null)
            {
                throw new Exception($"Blockchain not found. Id: {@event.BlockchainId}");
            }

            var vault = await _vaultsRepository.GetByIdAsync(@event.VaultId);

            if (vault == null)
            {
                throw new Exception($"Vault not found. Id: {@event.VaultId}");
            }

            var walletGenerationRequest = new WalletGenerationRequest
            {
                Id              = @event.WalletGenerationRequestId,
                TenantId        = @event.TenantId,
                VaultId         = @event.VaultId,
                RejectionReason = @event.RejectionReason == null
                    ? (WalletRejectionReason?)null
                    : @event.RejectionReason.Value switch
                {
                    RejectionReason.Other => WalletRejectionReason.Other,
                    RejectionReason.UnknownBlockchain => WalletRejectionReason.UnknownBlockchain,
                    _ => throw new ArgumentOutOfRangeException(nameof(@event.RejectionReason.Value),
                                                               @event.RejectionReason.Value,
                                                               null)
                },
        public async Task Consume(ConsumeContext <TransferSigningRequestUpdated> context)
        {
            var @event = context.Message;

            var blockchain = await _blockchainsRepository.GetByIdAsync(@event.BlockchainId);

            if (blockchain == null)
            {
                throw new Exception($"Blockchain not found. Id: {@event.BlockchainId}");
            }

            var vault = await _vaultsRepository.GetByIdAsync(@event.VaultId);

            if (vault == null)
            {
                throw new Exception($"Vault not found. Id: {@event.VaultId}");
            }

            var transactionSigningRequest = new TransferSigningRequest
            {
                Id         = @event.Id,
                TransferId = @event.TransferId,
                TenantId   = @event.TenantId,
                VaultId    = @event.VaultId,
                VaultType  = vault.Type,
                Blockchain = new Blockchain
                {
                    Id           = @event.BlockchainId,
                    NetworkType  = blockchain.NetworkType,
                    ProtocolCode = blockchain.Protocol.Code,
                    DoubleSpendingProtectionType = blockchain.Protocol.DoubleSpendingProtectionType
                },
                BuiltTransaction = @event.BuiltTransaction,
                SigningAddresses = @event.SigningAddresses,
                CoinsToSpend     = @event.CoinsToSpend
                                   ?.Select(x => new Common.ReadModels.TransferSigningRequests.Coin(x.Id, x.Asset, x.Value, x.Address, x.Redeem))
                                   .ToArray(),
                RejectionReason = @event.RejectionReason switch
                {
                    RejectionReason.Other => TransferRejectionReason.Other,
                    RejectionReason.UnknownBlockchain => TransferRejectionReason.UnknownBlockchain,
                    RejectionReason.UnwantedTransaction => TransferRejectionReason.UnwantedTransaction,
                    null => null,
                    _ => throw new ArgumentOutOfRangeException(nameof(@event.RejectionReason),
                                                               @event.RejectionReason,
                                                               null)
                },
Example #3
0
        public async Task Consume(ConsumeContext <TransferValidationRequestUpdated> context)
        {
            var @event = context.Message;

            var vault = await _vaultsRepository.GetByIdAsync(@event.VaultId);

            if (vault == null)
            {
                throw new Exception($"Vault not found. Id: {@event.VaultId}");
            }

            var blockchain = await _blockchainsRepository.GetByIdAsync(@event.BlockchainId);

            if (blockchain == null)
            {
                throw new Exception($"Blockchain not found. Id: {@event.BlockchainId}");
            }

            var transferValidationRequest = new TransferValidationRequest
            {
                Id         = @event.Id,
                TransferId = @event.TransferId,
                TenantId   = @event.TenantId,
                VaultId    = @event.VaultId,
                VaultType  = vault.Type,
                Blockchain = new Blockchain
                {
                    Id           = @event.BlockchainId,
                    NetworkType  = blockchain.NetworkType,
                    ProtocolCode = blockchain.Protocol.Code
                },
                Asset = new Common.ReadModels.TransferValidationRequests.Asset
                {
                    Address = @event.Asset.Address,
                    Id      = @event.Asset.Id,
                    Symbol  = @event.Asset.Symbol
                },
                SourceAddress =
                    new Common.ReadModels.TransferValidationRequests.SourceAddress()
                {
                    Name    = @event.SourceAddress.Name,
                    Group   = @event.SourceAddress.Group,
                    Address = @event.SourceAddress.Address
                },
                DestinationAddress =
                    new Common.ReadModels.TransferValidationRequests.DestinationAddress()
                {
                    Address = @event.DestinationAddress.Address,
                    Group   = @event.DestinationAddress.Group,
                    Name    = @event.DestinationAddress.Name,
                    Tag     = @event.DestinationAddress.Tag,
                    TagType = @event.DestinationAddress.TagType
                },
                Amount          = @event.Amount,
                FeeLimit        = @event.FeeLimit,
                TransferContext = new Common.ReadModels.TransferValidationRequests.TransferContext
                {
                    AccountReferenceId    = @event.TransferContext.AccountReferenceId,
                    WithdrawalReferenceId = @event.TransferContext.WithdrawalReferenceId,
                    Component             = @event.TransferContext.Component,
                    OperationType         = @event.TransferContext.OperationType,
                    SourceGroup           = @event.TransferContext.SourceGroup,
                    DestinationGroup      = @event.TransferContext.DestinationGroup,
                    Document       = @event.TransferContext.Document,
                    Signature      = @event.TransferContext.Signature,
                    RequestContext = new Common.ReadModels.TransferValidationRequests.RequestContext
                    {
                        UserId    = @event.TransferContext.RequestContext.UserId,
                        ApiKeyId  = @event.TransferContext.RequestContext.ApiKeyId,
                        Ip        = @event.TransferContext.RequestContext.Ip,
                        Timestamp = @event.TransferContext.RequestContext.Timestamp
                    }
                },
                Document        = @event.Document,
                Signature       = @event.Signature,
                RejectionReason = [email protected]
                    ? (Common.ReadModels.TransferValidationRequests.TransferValidationRequestRejectionReason?)null
                                  : @event.RejectionReason.Value switch
                {
                    Swisschain.Sirius.VaultAgent.MessagingContract.TransferValidationRequests
                    .TransferValidationRequestRejectionReason.Other =>
                    Common.ReadModels.TransferValidationRequests.TransferValidationRequestRejectionReason.Other,
                    Swisschain.Sirius.VaultAgent.MessagingContract.TransferValidationRequests
                    .TransferValidationRequestRejectionReason.RejectedByPolicy =>
                    Common.ReadModels.TransferValidationRequests.TransferValidationRequestRejectionReason
                    .RejectedByPolicy,
                    _ => throw new ArgumentOutOfRangeException(nameof(@event.RejectionReason),
                                                               @event.RejectionReason,
                                                               null)
                },