public static KeyValuePair <string, string> DeployDefaultPensionFund( int gasLimit, string pensionFundAddress, string employerAddress, string employeeAddress, double pensionFundFee, double pensionFundLatePenalty, double auctusFee, double maxSalaryBonus, double employeeContribution, double employeeContributionBonus, double employeeSalary, Dictionary <string, double> referenceValues, Dictionary <int, double> bonusVestingDistribuition) { int rateDecimals = 4; string smartContractStringified = DemoSmartContracts.DEFAULT_PENSION_FUND_SC .Replace("{PENSION_FUND_ADDRESS}", pensionFundAddress) .Replace("{EMPLOYER_ADDRESS}", employerAddress) .Replace("{EMPLOYEE_ADDRESS}", employeeAddress) .Replace("{PENSION_FUND_FEE}", Web3.GetNumberFormatted(pensionFundFee, rateDecimals)) .Replace("{PENSION_FUND_LATE_PENALTY}", Web3.GetNumberFormatted(pensionFundLatePenalty, rateDecimals)) .Replace("{AUCTUS_FEE}", Web3.GetNumberFormatted(auctusFee, rateDecimals)) .Replace("{MAX_SALARY_BONUS}", Web3.GetNumberFormatted(maxSalaryBonus, rateDecimals)) .Replace("{EMPLOYEE_CONTRIBUTION}", Web3.GetNumberFormatted(employeeContribution, rateDecimals)) .Replace("{EMPLOYEE_CONTRIBUTION_BONUS}", Web3.GetNumberFormatted(employeeContributionBonus, rateDecimals)) .Replace("{EMPLOYEE_SALARY}", Web3.GetNumberFormatted(employeeSalary, 12)) .Replace("{REFERENCE_VALUE_ADDRESS}", string.Join("\n\t\t", referenceValues.Select(c => string.Format("reference.push(Reference({0}, {1}));", c.Key, Web3.GetNumberFormatted(c.Value, rateDecimals))))) .Replace("{BONUS_DISTRIBUTION}", string.Join("\n\t\t", bonusVestingDistribuition.Select(c => string.Format("bonusDistribution.push(BonusVesting({0}, {1}));", c.Key.ToString(), Web3.GetNumberFormatted(c.Value, rateDecimals))))); SCCompiled scCompiled = Solc.Compile("CompanyContract", smartContractStringified).Single(c => c.Name == "CompanyContract"); string transactionHash = Web3.DeployContract(scCompiled, gasLimit, GWEI_FAST); return(new KeyValuePair <string, string>(transactionHash, smartContractStringified)); }
private void ParseOutput(string output, string subtitle, string propertyNameToBeSet) { string[] initialSplit = output.Split(new string[] { subtitle, "\n", "\r", " ", "=" }, StringSplitOptions.RemoveEmptyEntries); SCCompiled scCompiled; //Reverse iteration in pairs for (int i = initialSplit.Length - 1; i >= 0; i = i - 2) { if (initialSplit[i].Contains(BaseFilePath)) { i = i + 1; //It is a interface, so with empty BIN, go to the next skipping only one } else { string name = initialSplit[i - 1].Split(':').Last(); scCompiled = CompiledData.Where(c => c.Name == name).FirstOrDefault(); bool newSC = scCompiled == null; if (newSC) { scCompiled = new SCCompiled(); scCompiled.Name = name; } scCompiled.GetType().GetProperty(propertyNameToBeSet, BindingFlags.Public | BindingFlags.Instance).SetValue(scCompiled, initialSplit[i]); if (newSC) { CompiledData.Add(scCompiled); } } } }
internal static string DeployContract(SCCompiled sc, int gasLimit, int gweiGasPrice, KeyValuePair <string, string> ownerAddressEncryptedPassword = default(KeyValuePair <string, string>)) { if (sc == null || string.IsNullOrEmpty(sc.Name) || (string.IsNullOrEmpty(sc.Binary) && (string.IsNullOrEmpty(sc.ABI) || sc.ABI == "[]"))) { throw new Web3Exception("Invalid compiled smart contract."); } ValidateGasValues(gasLimit, gweiGasPrice); ownerAddressEncryptedPassword = GetSourceAddres(ownerAddressEncryptedPassword); return(new Web3().InternalDeployContract(sc, gasLimit, gweiGasPrice, ownerAddressEncryptedPassword)); }
private string InternalDeployContract(SCCompiled sc, int gasLimit, int gweiGasPrice, KeyValuePair <string, string> ownerAddressEncryptedPassword) { DeployInfo = new DeployData() { ABI = sc.ABI, Address = ownerAddressEncryptedPassword.Key, Binary = sc.Binary, GasLimit = gasLimit, GasPrice = GetBigNumberFormatted(new BigNumber(gweiGasPrice, 9)), Name = sc.Name }; ABIVariableInfo = new BigVariableData() { BaseName = string.Format("abi{0}", DeployInfo.Name), RemainingString = DeployInfo.ABI, SplitCounter = 0, VariableNames = new List <string>(), NextFunction = SetBinaryBigVariableCommand }; BinaryVariableInfo = new BigVariableData() { BaseName = string.Format("bin{0}", DeployInfo.Name), RemainingString = string.Format("0x{0}", DeployInfo.Binary), SplitCounter = 0, VariableNames = new List <string>(), NextFunction = DeployCommand }; ConsoleOutput output = Execute(GetUnlockAccountCommand(ownerAddressEncryptedPassword.Key, ownerAddressEncryptedPassword.Value, SetABIBigVariableCommand)); if (!output.Ok || !output.Output.Contains("transactionHash")) { throw new Web3Exception(string.Format("Error to deploy contract.\n\n{0}", output.Output)); } return(output.Output.Split(new string[] { "transactionHash:" }, StringSplitOptions.RemoveEmptyEntries).Last().Trim(' ', '\n', '\r', '}', '"')); }