public async Task HandleAsync(string[] topics, string data, string contractAddress)
        {
            //This means that the event is raised by another smart contract and we are not interested in it
            if (!string.Equals(contractAddress,
                               _settingsService.GetPrivateBlockchainGatewayContractAddress(),
                               StringComparison.InvariantCultureIgnoreCase))
            {
                _log.Info("The contract address differs from the expected one. Event handling will be stopped.",
                          new { expected = _settingsService.GetPrivateBlockchainGatewayContractAddress(), current = contractAddress });

                return;
            }

            var eventType = _blockchainEventDecoder.GetEventType(topics[0]);

            switch (eventType)
            {
            case BlockchainEventType.Unknown:
                return;

            case BlockchainEventType.PublicAccountLinked:
                await HandleWalletLinkedAsync(topics, data);

                break;

            case BlockchainEventType.PublicAccountUnlinked:
                await HandleWalletUnlinkedAsync(topics, data);

                break;

            default: throw new InvalidOperationException("Unsupported blockchain event type");
            }
        }
        public async Task HandleAsync(string[] topics, string data, string contractAddress, string operationId, string txHash)
        {
            //This means that the event is raised by another smart contract and we are not interested in it
            if (!string.Equals(contractAddress, _settingsService.GetPrivateBlockchainGatewayContractAddress()
                               , StringComparison.InvariantCultureIgnoreCase))
            {
                _log.Info("The contract address differs from the expected one. Event handling will be stopped.",
                          new { expected = _settingsService.GetPrivateBlockchainGatewayContractAddress(), current = contractAddress });

                return;
            }

            var isDuplicate = await _deduplicationLogRepository.IsDuplicateAsync(operationId);

            if (isDuplicate)
            {
                _log.Warning(message: "Duplicated event found, processing won't continue further", context: operationId);
                return;
            }

            var eventType = _blockchainEventDecoder.GetEventType(topics[0]);

            switch (eventType)
            {
            case BlockchainEventType.Unknown:
                return;

            case BlockchainEventType.TransferredFromPublicNetwork:
                await HandleTransferToInternalAsync(topics, data, operationId);

                break;

            case BlockchainEventType.TransferredToPublicNetwork:
                await HandleTransferToExternalAsync(topics, data, operationId, txHash);

                break;

            default: throw new InvalidOperationException("Unsupported blockchain event type");
            }
        }
Beispiel #3
0
        public async Task HandleAsync(string[] topics, string data, string contractAddress, DateTime timestamp)
        {
            //This means that the event is raised by another smart contract and we are not interested in it
            if (!string.Equals(contractAddress, _settingsService.GetPartnersPaymentsAddress()
                               , StringComparison.InvariantCultureIgnoreCase))
            {
                _log.Info("The contract address differs from the expected one. Event handling will be stopped.",
                          context: new { expected = _settingsService.GetPartnersPaymentsAddress(), current = contractAddress });

                return;
            }

            var eventType = _eventDecoder.GetEventType(topics[0]);

            switch (eventType)
            {
            case BlockchainEventType.Unknown:
                return;

            case BlockchainEventType.TransferReceived:
                await HandlePaymentReceived(topics, data, timestamp);

                break;

            case BlockchainEventType.TransferAccepted:
                await HandlePaymentAccepted(topics, data, timestamp);

                break;

            case BlockchainEventType.TransferRejected:
                await HandlePaymentRejected(topics, data);

                break;

            default: throw new InvalidOperationException("Unsupported blockchain event type");
            }
        }