Exemple #1
0
        public async Task VerifyAsync(VerifyRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var document = new HtmlDocument();

            using (var client = HttpClientFactory.CreateFirefox(m_ServiceUri))
                using (var getResponse = await client.GetAsync(m_ServiceUri))
                    document.LoadHtml(await getResponse.Content.ReadAsStringAsync());
            var hiddenFields = document.DocumentNode
                               .SelectNodes("//input[@type='hidden']");
            var postValues = hiddenFields
                             .Select(x => new
            {
                Key   = x.GetAttributeValue("id", null),
                Value = x.GetAttributeValue("value", "")
            })
                             .Where(x => !string.IsNullOrEmpty(x.Key))
                             .GroupBy(x => x.Key)
                             .ToDictionary(x => x.Key, x => HtmlEntity.DeEntitize(x.First().Value));

            postValues["ctl00$ContentPlaceHolder1$txtContractAddress"]       = request.ContractAddress;
            postValues["ctl00$ContentPlaceHolder1$txtContractName"]          = request.Name;
            postValues["ctl00$ContentPlaceHolder1$ddlCompilerVersions"]      = $"v{request.Compiler}";
            postValues["ctl00$ContentPlaceHolder1$ddlOptimization"]          = "1";
            postValues["ctl00$ContentPlaceHolder1$txtSourceCode"]            = request.Source;
            postValues["ctl00$ContentPlaceHolder1$txtConstructorArguements"] = HexHelper.ToHex(request.AbiEncodedConstructorArgs);
            //postValues["ctl00$ContentPlaceHolder1$txtRuns"] = "200";
            for (var i = 1; i <= 5; i++)
            {
                postValues["ctl00$ContentPlaceHolder1$txtLibraryName" + i]    = string.Empty;
                postValues["ctl00$ContentPlaceHolder1$txtLibraryAddress" + i] = "0x";
            }
            postValues["ctl00$ContentPlaceHolder1$btnSubmit"]      = "Verify And Publish";
            postValues["ctl00$ContentPlaceHolder1$txtGithubGist"]  = string.Empty;
            postValues["ctl00$ContentPlaceHolder1$hdnSelectedTab"] = "'bytecode'";
            postValues["ctl00$ContentPlaceHolder1$libcounter"]     = "1";

            using (var client = HttpClientFactory.CreateFirefox(m_ServiceUri))
                using (var postResponse = await client.PostAsync(m_ServiceUri, new FormUrlEncodedContent(postValues)))
                {
                    postResponse.EnsureSuccessStatusCode();
                    document.LoadHtml(await postResponse.Content.ReadAsStringAsync());
                }
            if (document.DocumentNode.SelectSingleNode(
                    "//font[@color='green' and contains(.,'Successfully generated ByteCode and ABI')]") != null)
            {
                return;
            }
            var errorText = document.DocumentNode.SelectSingleNode(
                "//span[@id='ContentPlaceHolder1_lblErrorStatus']");

            if (string.IsNullOrWhiteSpace(errorText?.InnerText))
            {
                errorText = document.DocumentNode.SelectSingleNode(
                    "//span[@id='ContentPlaceHolder1_lblResult']");
            }
            throw new ContractVerificationException("Verification failed: " + errorText?.InnerText);
        }