예제 #1
0
        private bool TryDecode(EventABI[] abis, FilterLog log, out DecodedEvent decodedEvent)
        {
            decodedEvent = null;

            if (abis == null || abis.Length == 0)
            {
                decodedEvent = log.ToDecodedEvent();
                return(true);
            }

            var abi = abis.FirstOrDefault(a => log.IsLogForEvent(a.Sha3Signature));

            if (abi is null)
            {
                return(false);
            }

            try
            {
                decodedEvent = log.ToDecodedEvent(abi);
                return(true);
            }
            catch (Exception x) when(x.IsEventDecodingIndexMisMatch())
            {
                return(false);
            }
        }
예제 #2
0
        private bool TryDecode(EventABI[] abis, FilterLog log, out DecodedEvent decodedEvent)
        {
            decodedEvent = null;

            if (abis == null || abis.Length == 0)
            {
                decodedEvent = log.ToDecodedEvent();
                return(true);
            }


            var abi = abis.FirstOrDefault(a => a.IsLogForEvent(log));

            if (abi is null)
            {
                return(false);
            }

            try
            {
                decodedEvent = log.ToDecodedEvent(abi);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public async Task IsEmpty()
        {
            var config = new EventRuleDto
            {
                Type   = EventRuleType.Empty,
                Source = EventRuleSource.EventParameter,
                EventParameterNumber = 1
            };

            var rule = new EventRule(_mockEventSubscription.Object, 1, config);

            var decodedEvent = _sampleTransferLog.ToDecodedEvent(_transferEventAbi);

            Assert.False(await rule.HandleAsync(decodedEvent));

            decodedEvent.Event.First(p => p.Parameter.Order == config.EventParameterNumber).Result = null;
            Assert.True(await rule.HandleAsync(decodedEvent));

            decodedEvent.Event.First(p => p.Parameter.Order == config.EventParameterNumber).Result = string.Empty;
            Assert.True(await rule.HandleAsync(decodedEvent));
        }
예제 #4
0
        public void ToDecodedEventWithNullAbi()
        {
            var log          = new FilterLog {
            };
            var decodedEvent = log.ToDecodedEvent();

            Assert.NotNull(decodedEvent);
            Assert.Empty(decodedEvent.Event);
            Assert.Same(log, decodedEvent.Log);

            Assert.Null(decodedEvent.State["EventAbiName"]);
            Assert.Null(decodedEvent.State["EventSignature"]);
            Assert.Null(decodedEvent.State["TransactionHash"]);
            Assert.Null(decodedEvent.State["LogIndex"]);
            Assert.Equal(0, decodedEvent.State["HandlerInvocations"]);
            Assert.True(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() >= (long)decodedEvent.State["UtcNowMs"]);
        }
예제 #5
0
        private bool TryDecode <TEventDto>(FilterLog log, EventABI abi, out DecodedEvent decodedEvent) where TEventDto : new()
        {
            decodedEvent = null;

            if (abi is null)
            {
                return(false);
            }

            try
            {
                decodedEvent = log.ToDecodedEvent <TEventDto>(abi);
                return(true);
            }
            catch (Exception x) when(x.IsEventDecodingIndexMisMatch())
            {
                return(false);
            }
        }
예제 #6
0
        private bool TryDecode <TEventDto>(FilterLog log, EventABI abi, out DecodedEvent decodedEvent) where TEventDto : new()
        {
            decodedEvent = null;

            if (abi is null)
            {
                return(false);
            }

            try
            {
                decodedEvent = log.ToDecodedEvent <TEventDto>(abi);
                return(true);
            }
            catch
            {
                return(false);
            }
        }