From 502c417a518606dc273132b2afbf4774d596cf95 Mon Sep 17 00:00:00 2001 From: lwyeo Date: Wed, 31 Oct 2018 19:08:56 +0800 Subject: [PATCH] Fixed pool mining does not check for maximum target --- .../NetworkInterface/Web3Interface.cs | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/SoliditySHA3Miner/NetworkInterface/Web3Interface.cs b/SoliditySHA3Miner/NetworkInterface/Web3Interface.cs index 4211dc9..9cdec55 100644 --- a/SoliditySHA3Miner/NetworkInterface/Web3Interface.cs +++ b/SoliditySHA3Miner/NetworkInterface/Web3Interface.cs @@ -140,7 +140,58 @@ public Web3Interface(string web3ApiPath, string contractAddress, string minerAdd var contractABI = m_contract.ContractBuilder.ContractABI; FunctionABI mintABI = null; - if (!string.IsNullOrWhiteSpace(privateKey)) + if (string.IsNullOrWhiteSpace(privateKey)) // look for maximum target method only + { + if (m_MAXIMUM_TARGET == null) + { + #region ERC918 methods + + if (contractABI.Functions.Any(f => f.Name == "MAX_TARGET")) + m_MAXIMUM_TARGET = m_contract.GetFunction("MAX_TARGET"); + + #endregion + + #region ABI methods checking + + if (m_MAXIMUM_TARGET == null) + { + var maxTargetNames = new string[] { "MAX_TARGET", "MAXIMUM_TARGET", "maxTarget", "maximumTarget" }; + + // ERC541 backwards compatibility + if (contractABI.Functions.Any(f => f.Name == "_MAXIMUM_TARGET")) + { + m_MAXIMUM_TARGET = m_contract.GetFunction("_MAXIMUM_TARGET"); + } + else + { + var maxTargetABI = contractABI.Functions. + FirstOrDefault(function => + { + return maxTargetNames.Any(targetName => + { + return function.Name.IndexOf(targetName, StringComparison.OrdinalIgnoreCase) > -1; + }); + }); + if (maxTargetABI == null) + m_MAXIMUM_TARGET = null; // Mining still can proceed without MAX_TARGET + else + { + if (!maxTargetABI.OutputParameters.Any()) + Program.Print(string.Format("[ERROR] '{0}' function must have output parameter.", maxTargetABI.Name)); + + else if (maxTargetABI.OutputParameters[0].Type != "uint256") + Program.Print(string.Format("[ERROR] '{0}' function output parameter type must be uint256.", maxTargetABI.Name)); + + else + m_MAXIMUM_TARGET = m_contract.GetFunction(maxTargetABI.Name); + } + } + } + + #endregion + } + } + else { m_gasToMine = gasToMine; Program.Print(string.Format("[INFO] Gas to mine: {0}", m_gasToMine));