Skip to content

Commit

Permalink
Fixed pool mining does not check for maximum target
Browse files Browse the repository at this point in the history
  • Loading branch information
lwYeo committed Oct 31, 2018
1 parent db5d915 commit 502c417
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion SoliditySHA3Miner/NetworkInterface/Web3Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 502c417

Please sign in to comment.