public SimpleRpcClient(IUserOutput userOutput, IPasswordRegistry passwordRegistry, X509Certificate2 certificate, ILogger logger, SigningContext signingContextProvider) { _logger = logger; _certificate = certificate; var fileSystem = new FileSystem(); var consolePasswordReader = new ConsolePasswordReader(userOutput, new ConsoleUserInput()); var passwordManager = new PasswordManager(consolePasswordReader, passwordRegistry); var cryptoContext = new FfiWrapper(); var hashProvider = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("keccak-256")); var peerSettings = Substitute.For <IPeerSettings>(); peerSettings.NetworkType.Returns(signingContextProvider.NetworkType); var localKeyStore = new LocalKeyStore(passwordManager, cryptoContext, fileSystem, hashProvider, _logger); var keyRegistry = new KeyRegistry(); var keySigner = new KeySigner(localKeyStore, cryptoContext, keyRegistry); var memoryCacheOptions = new MemoryCacheOptions(); var memoryCache = new MemoryCache(memoryCacheOptions); var changeTokenProvider = new TtlChangeTokenProvider(10000); var messageCorrelationManager = new RpcMessageCorrelationManager(memoryCache, _logger, changeTokenProvider); var peerIdValidator = new PeerIdValidator(cryptoContext); var nodeRpcClientChannelFactory = new RpcClientChannelFactory(keySigner, messageCorrelationManager, peerIdValidator, peerSettings); var eventLoopGroupFactoryConfiguration = new EventLoopGroupFactoryConfiguration { TcpClientHandlerWorkerThreads = 4 }; var tcpClientEventLoopGroupFactory = new TcpClientEventLoopGroupFactory(eventLoopGroupFactoryConfiguration); var handlers = new List <IRpcResponseObserver> { new BroadcastRawTransactionResponseObserver(_logger), new GetVersionResponseObserver(_logger) }; _rpcClientFactory = new RpcClientFactory(nodeRpcClientChannelFactory, tcpClientEventLoopGroupFactory, handlers); //PeerId for RPC/TCP is currently redundant. var publicKey = keyRegistry.GetItemFromRegistry(KeyRegistryTypes.DefaultKey).GetPublicKey().Bytes; _senderPeerId = publicKey.BuildPeerIdFromPublicKey(IPAddress.Any, 1026); }
public async Task TcpClientChannelFactory_BuildChannel_Should_Return_IObservableChannel() { var eventLoopGroupFactoryConfiguration = new EventLoopGroupFactoryConfiguration { TcpClientHandlerWorkerThreads = 2 }; var eventLoopGroupFactory = new TcpClientEventLoopGroupFactory(eventLoopGroupFactoryConfiguration); var ipAddress = IPAddress.Loopback; var port = 9000; var testTcpClientChannelFactory = new TestTcpClientChannelFactory(); var channel = await testTcpClientChannelFactory.BuildChannelAsync(eventLoopGroupFactory, ipAddress, port).ConfigureAwait(false); channel.Should().BeOfType <ObservableChannel>(); }