Esempio n. 1
0
        public async Task RequestCrossChainData_Test()
        {
            var chainId       = ChainHelper.GetChainId(ChainHelper.ConvertBase58ToChainId("AELF") + 1);
            var remoteChainId = ChainOptions.ChainId;
            var height        = 2;
            var port          = 5000;
            await Server.StartAsync(port);

            var grpcClientInitializationContext = new GrpcClientInitializationContext
            {
                RemoteChainId = chainId,
                LocalChainId  = ChainHelper.ConvertBase58ToChainId("AELF"),
                DialTimeout   = 1000,
                UriStr        = string.Concat(Host, ":", port)
            };
            var client = new ClientForSideChain(grpcClientInitializationContext);

            _grpcCrossChainCommunicationTestHelper.GrpcCrossChainClients.TryAdd(remoteChainId, client);
            _grpcCrossChainCommunicationTestHelper.FakeSideChainBlockDataEntityCacheOnServerSide(height);
            await client.RequestCrossChainDataAsync(height, b => _blockCacheEntityProducer.TryAddBlockCacheEntity(b));

            var clientBlockDataEntityCache = GrpcCrossChainCommunicationTestHelper.ClientBlockDataEntityCache;
            var sideChainBlockData         = new SideChainBlockData {
                Height = height
            };

            Assert.Contains(sideChainBlockData, clientBlockDataEntityCache);
            Dispose();
        }
Esempio n. 2
0
 protected GrpcCrossChainClient(GrpcClientInitializationContext grpcClientInitializationContext)
 {
     _localChainId    = grpcClientInitializationContext.LocalChainId;
     RemoteChainId    = grpcClientInitializationContext.RemoteChainId;
     DialTimeout      = grpcClientInitializationContext.DialTimeout;
     Channel          = CreateChannel(grpcClientInitializationContext.UriStr);
     _basicGrpcClient = new BasicCrossChainRpc.BasicCrossChainRpcClient(Channel);
     _listeningPort   = grpcClientInitializationContext.ListeningPort;
 }
Esempio n. 3
0
        public async Task RequestChainInitializationData_ParentClient_Test()
        {
            var chainId = ChainHelper.GetChainId(ChainHelper.ConvertBase58ToChainId("AELF") + 1);
            await Server.StartAsync(5000);

            var grpcClientInitializationContext = new GrpcClientInitializationContext
            {
                LocalChainId  = chainId,
                RemoteChainId = ChainHelper.ConvertBase58ToChainId("AELF"),
                DialTimeout   = 1000,
                UriStr        = string.Concat(Host, ":", "5000")
            };
            var client = new ClientForParentChain(grpcClientInitializationContext);
            var res    = await client.RequestChainInitializationDataAsync(chainId);

            Assert.Equal(1, res.CreationHeightOnParentChain);
            Dispose();
        }
        /// <summary>
        /// Create a new client to another chain.
        /// </summary>
        /// <returns>
        /// </returns>
        public ICrossChainClient CreateCrossChainClient(CrossChainClientDto crossChainClientDto)
        {
            var clientInitializationContext = new GrpcClientInitializationContext
            {
                DialTimeout   = _grpcCrossChainConfigOption.ConnectionTimeout,
                LocalChainId  = crossChainClientDto.LocalChainId,
                ListeningPort = _grpcCrossChainConfigOption.ListeningPort,
                RemoteChainId = crossChainClientDto.RemoteChainId
            };

            if (crossChainClientDto.IsClientToParentChain)
            {
                clientInitializationContext.UriStr = GetUriStr(_grpcCrossChainConfigOption.ParentChainServerIp,
                                                               _grpcCrossChainConfigOption.ParentChainServerPort);
                return(new ClientForParentChain(clientInitializationContext));
            }

            clientInitializationContext.UriStr = GetUriStr(crossChainClientDto.RemoteServerHost,
                                                           crossChainClientDto.RemoteServerPort);
            return(new ClientForSideChain(clientInitializationContext));
        }
Esempio n. 5
0
 public ClientForParentChain(GrpcClientInitializationContext grpcClientInitializationContext)
     : base(grpcClientInitializationContext)
 {
     GrpcClient = new ParentChainRpc.ParentChainRpcClient(Channel);
 }
Esempio n. 6
0
 public ClientForSideChain(GrpcClientInitializationContext grpcClientInitializationContext)
     : base(grpcClientInitializationContext)
 {
     GrpcClient = new SideChainRpc.SideChainRpcClient(Channel);
 }