Esempio n. 1
0
        public static TEventDTO DecodeEvent <TEventDTO>(this TEventDTO eventDTO, EventABI eventABI, FilterLog log) where TEventDTO : IEventDTO
        {
            if (!IsLogForEvent(eventABI, log))
            {
                return(default(TEventDTO));
            }
            var eventDecoder = new EventTopicDecoder();

            return(eventDecoder.DecodeTopics(eventDTO, log.Topics, log.Data));
        }
        public T DecodeEvent <T>(Event eventHandler) where T : new()
        {
            if (!eventHandler.IsLogForEvent(this))
            {
                return(default(T));
            }

            var decoder = new EventTopicDecoder();

            return(decoder.DecodeTopics <T>(Topics, Data));
        }
Esempio n. 3
0
        public static EventLog <TEventDTO> DecodeEvent <TEventDTO>(this EventABI eventABI, FilterLog log) where TEventDTO : new()
        {
            if (!IsLogForEvent(eventABI, log))
            {
                return(null);
            }
            var eventDecoder = new EventTopicDecoder();
            var eventObject  = eventDecoder.DecodeTopics <TEventDTO>(log.Topics, log.Data);

            return(new EventLog <TEventDTO>(eventObject, log));
        }
        protected override async Task ProcessMessageAsync(UndecodedEvent message)
        {
            if (!message.OriginAddress.Equals(_contractAddress, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            try
            {
                var signature = message.Topics[0];

                if (signature.Equals(_transferReceivedEventSignature, StringComparison.OrdinalIgnoreCase))
                {
                    var @event = _eventTopicDecoder.DecodeTopics <TransferReceivedEventDTO>(
                        message.Topics.Select(o => (object)o).ToArray(), message.Data);

                    await _purchaseService.ConfirmAsync(Guid.Parse(@event.TransferId));

                    _log.Info("Transfer receiver event handled.", context: $"transferId: {@event.TransferId}");
                }
                else if (signature.Equals(_transferAcceptedEventSignature, StringComparison.OrdinalIgnoreCase))
                {
                    var @event = _eventTopicDecoder.DecodeTopics <TransferAcceptedEventDTO>(
                        message.Topics.Select(o => (object)o).ToArray(), message.Data);

                    await _operationsService.HandleSucceededTransferAsync(Guid.Parse(@event.TransferId));
                }
                else if (signature.Equals(_transferRejectedEventSignature, StringComparison.OrdinalIgnoreCase))
                {
                    var @event = _eventTopicDecoder.DecodeTopics <TransferRejectedEventDTO>(
                        message.Topics.Select(o => (object)o).ToArray(), message.Data);

                    await _operationsService.HandleFailedTransferAsync(Guid.Parse(@event.TransferId));
                }
            }
            catch (Exception exception)
            {
                _log.Error(exception, "An error occurred while processing undecoded event.",
                           $"transactionHash: {message.TransactionHash}");
            }
        }
Esempio n. 5
0
        public List <EventLog <T> > DecodeAllEvents <T>(FilterLog[] logs) where T : new()
        {
            var result       = new List <EventLog <T> >();
            var eventDecoder = new EventTopicDecoder();

            foreach (var log in logs)
            {
                var eventObject = eventDecoder.DecodeTopics <T>(log.Topics, log.Data);
                result.Add(new EventLog <T>(eventObject, log));
            }
            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Decodes event data into event DTO.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>Decoded event DTO.</returns>
        /// <see href="https://nethereum.readthedocs.io/en/latest/contracts/calling-transactions-events/"/>
        public T DecodeEventDTO <T>() where T : new()
        {
            EventTopicDecoder eventTopicDecoder = new EventTopicDecoder();

            object[] topicStrings = new object[this.Topics.Length];
            for (int i = 0; i < this.Topics.Length; i++)
            {
                topicStrings[i] = CryptoUtils.BytesToHexString(this.Topics[i]);
            }

            return(eventTopicDecoder.DecodeTopics <T>(topicStrings, CryptoUtils.BytesToHexString(this.Data)));
        }
 public T As <T>() where T : new()
 {
     try {
         return(decoder_.DecodeTopics <T>(Topics.ToArray(), Data));
     } catch (System.Exception ex) {
         Debug.Log("fail to convert to " + typeof(T) + " => " + ex.Message + " at " + ex.StackTrace);
         if (ex.InnerException != null)
         {
             Debug.Log("caused by " + ex.InnerException.Message);
         }
         return(default(T));
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Decodes event data into event DTO.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>Decoded event DTO.</returns>
        /// <see href="https://nethereum.readthedocs.io/en/latest/contracts/calling-transactions-events/"/>
        public T DecodeEventDTO <T>() where T : new()
        {
            EventTopicDecoder eventTopicDecoder = new EventTopicDecoder();

            return(eventTopicDecoder.DecodeTopics <T>(this.Topics, CryptoUtils.BytesToHexString(this.Data)));
        }
 private T DecodeEvent <T>(IEnumerable <string> topics, string data) where T : class, new()
 => _eventTopicDecoder.DecodeTopics <T>(topics.Select(o => (object)o).ToArray(), data);
 private T DecodeEvent <T>(string[] topics, string data) where T : class, new()
 => _eventTopicDecoder.DecodeTopics <T>(topics, data);