Exemplo n.º 1
0
        public async Task <string> GetHubAddressAsync(string contractAddress)
        {
            var getHubAddr        = new GetHubAddrFunction();
            var getHubAddrHandler = _ethApiContractService.GetContractQueryHandler <GetHubAddrFunction>();
            var address           = await getHubAddrHandler
                                    .QueryAsync <string>(contractAddress, getHubAddr)
                                    .ConfigureAwait(false);

            if (address == null)
            {
                throw new Exception($"Contract does not support Gas Station Network");
            }

            var code = await _ethApiContractService.GetCode
                       .SendRequestAsync(address)
                       .ConfigureAwait(false);

            if (code.Length <= 2)
            {
                throw new Exception($"Relay hub is not deployed at address {address}");
            }

            var getHubVersion        = new VersionFunction();
            var getHubVersionHandler = _ethApiContractService.GetContractQueryHandler <VersionFunction>();
            var hubVersion           = await getHubVersionHandler
                                       .QueryAsync <string>(address, getHubVersion)
                                       .ConfigureAwait(false);

            if (!hubVersion.StartsWith("1"))
            {
                throw new Exception($"Unsupported relay hub version {hubVersion}");
            }

            return(address);
        }
Exemplo n.º 2
0
        public async void Succeeds_and_returns_a_correctly_formatted_value()
        {
            // Arrange
            var request = TestFactory.CreateHttpRequest();
            // Act
            var response = (OkObjectResult)await VersionFunction.Run(request, logger);

            // Assert
            Assert.Equal(200, response.StatusCode);
            Assert.True(Version.TryParse(response.Value.ToString(), out Version parsed));
        }
 public Task <string> VersionQueryAsync(VersionFunction versionFunction, BlockParameter blockParameter = null)
 {
     return(ContractHandler.QueryAsync <VersionFunction, string>(versionFunction, blockParameter));
 }