Exemple #1
0
        public async Task request_eth_should_fail_for_null_address()
        {
            _ethRequestService.UpdateFaucet(_faucetPeer);
            var ethRequested = await _ethRequestService.TryRequestEthAsync(null, 1);

            ethRequested.Should().BeFalse();
        }
        public async Task request_eth_should_fail_for_null_address()
        {
            _ethRequestService.UpdateFaucet(_faucetPeer);
            var ethRequested = await _ethRequestService.TryRequestEthAsync(null, 1);

            ethRequested.Should().Be(FaucetResponse.InvalidNodeAddress);
        }
        public IProtocolHandler Create(ISession session)
        {
            IProtocolHandler handler = _subprotocolFactory.Create(session);

            handler.ProtocolInitialized += (sender, args) =>
            {
                var ndmEventArgs = (NdmProtocolInitializedEventArgs)args;
                _protocolValidator.DisconnectOnInvalid(Protocol.Ndm, session, ndmEventArgs);
                if (_logger.IsTrace)
                {
                    _logger.Trace($"NDM version {handler.ProtocolVersion}: {session.RemoteNodeId}, host: {session.Node.Host}");
                }
                if (string.IsNullOrWhiteSpace(_ethRequestService.FaucetHost) ||
                    !session.Node.Host.Contains(_ethRequestService.FaucetHost))
                {
                    return;
                }

                INdmPeer?peer = handler as INdmPeer;
                if (peer != null)
                {
                    _ethRequestService.UpdateFaucet(peer);
                }
                else
                {
                    _logger.Warn($"NDM handler cannot serve as faucet since it is not implementing {nameof(INdmPeer)}");
                }
            };

            return(handler);
        }
Exemple #4
0
        public void Init()
        {
            _consumerService.AddressChanged += (_, e) =>
            {
                if (!(e.OldAddress is null) && e.OldAddress != Address.Zero)
                {
                    return;
                }

                AddCapability();
            };
            _protocolsManager.AddProtocol(Protocol.Ndm, session =>
            {
                var logger  = _logManager.GetClassLogger <ProtocolsManager>();
                var handler = _subprotocolFactory.Create(session);
                handler.ProtocolInitialized += (sender, args) =>
                {
                    var ndmEventArgs = (NdmProtocolInitializedEventArgs)args;

                    _protocolValidator.DisconnectOnInvalid(Protocol.Ndm, session, ndmEventArgs);
                    if (logger.IsTrace)
                    {
                        logger.Trace($"NDM version {handler.ProtocolVersion}: {session.RemoteNodeId}, host: {session.Node.Host}");
                    }
                    if (string.IsNullOrWhiteSpace(_ethRequestService.FaucetHost) ||
                        !session.Node.Host.Contains(_ethRequestService.FaucetHost))
                    {
                        return;
                    }

                    _ethRequestService.UpdateFaucet(handler as INdmPeer);
                };

                return(handler);
            });

            var consumerAddress = _consumerService.GetAddress();

            if ((consumerAddress is null || consumerAddress == Address.Zero) &&
                (_providerAddress is null || _providerAddress == Address.Zero))
            {
                return;
            }

            _protocolsManager.AddSupportedCapability(Capability);
            _protocolsManager.P2PProtocolInitialized += (sender, args) => { TryAddCapability(); };
        }
        public IProtocolHandler Create(ISession session)
        {
            var handler = _subprotocolFactory.Create(session);

            handler.ProtocolInitialized += (sender, args) =>
            {
                var ndmEventArgs = (NdmProtocolInitializedEventArgs)args;
                _protocolValidator.DisconnectOnInvalid(Protocol.Ndm, session, ndmEventArgs);
                if (_logger.IsTrace)
                {
                    _logger.Trace($"NDM version {handler.ProtocolVersion}: {session.RemoteNodeId}, host: {session.Node.Host}");
                }
                if (string.IsNullOrWhiteSpace(_ethRequestService.FaucetHost) ||
                    !session.Node.Host.Contains(_ethRequestService.FaucetHost))
                {
                    return;
                }

                _ethRequestService.UpdateFaucet(handler as INdmPeer);
            };

            return(handler);
        }