示例#1
0
        public void get_consumer_address_should_return_address()
        {
            _consumerService.GetAddress().Returns(TestItem.AddressA);
            var result = _rpc.ndm_getConsumerAddress();

            _consumerService.Received().GetAddress();
            result.Data.Should().Be(TestItem.AddressA);
        }
示例#2
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 ResultWrapper <Address> ndm_getConsumerAddress()
 => ResultWrapper <Address> .Success(_consumerService.GetAddress());