private Command ProcessBigVariableCommand(BigVariableData bigVariableData, Func <ConsoleOutput, Command> currentFunction) { Command nextCommand = new Command(); if (string.IsNullOrEmpty(bigVariableData.RemainingString)) { nextCommand.Comm = string.Format("var {0} = {1}", bigVariableData.BaseName, string.Join("+", bigVariableData.VariableNames)); nextCommand.ReturnFunction = bigVariableData.NextFunction; } else { ++bigVariableData.SplitCounter; string variableName = string.Format("{0}{1}", bigVariableData.BaseName, bigVariableData.SplitCounter); string commandInput = string.Format("var {0} = ", variableName); int remainingCharacters = MAX_CHAR_STAND_INPUT_WRITE - commandInput.Length - 2; //2 is for variable quotes //whether string variable is already lesser than maximun if (bigVariableData.RemainingString.Length <= (remainingCharacters + 1) && bigVariableData.VariableNames.Count == 0) { nextCommand.Comm = string.Format("var {0} = '{1}'", bigVariableData.BaseName, bigVariableData.RemainingString); nextCommand.ReturnFunction = bigVariableData.NextFunction; } else { string variable = bigVariableData.RemainingString.Substring(0, Math.Min(remainingCharacters, bigVariableData.RemainingString.Length)); bigVariableData.RemainingString = bigVariableData.RemainingString.Substring(variable.Length); nextCommand.Comm = string.Format("{0}'{1}'", commandInput, variable); nextCommand.ReturnFunction = currentFunction; bigVariableData.VariableNames.Add(variableName); } } return(nextCommand); }
private string InternalCallFunction(string scAddress, string abi, string functionName, string value, int gasLimit, int gweiGasPrice, KeyValuePair <string, string> fromAddressEncryptedPassword, params Variable[] parameters) { TransactionInfo = new TransactionData() { To = scAddress, From = fromAddressEncryptedPassword.Key, Value = value, GasLimit = gasLimit, GasPrice = GetBigNumberFormatted(new BigNumber(gweiGasPrice, 9)), Function = functionName, Parameters = GetParameterListFormatted(parameters) }; ABIVariableInfo = new BigVariableData() { BaseName = string.Format("abi{0}", functionName), RemainingString = abi, SplitCounter = 0, VariableNames = new List <string>(), NextFunction = CallFunctionCommand }; ConsoleOutput output = Execute(GetUnlockAccountCommand(fromAddressEncryptedPassword.Key, fromAddressEncryptedPassword.Value, SetABIBigVariableCommand)); if (!output.Ok || !output.Output.StartsWith("0x")) { throw new Web3Exception(string.Format("Error on call transaction function.\n\n{0}", output.Output)); } return(output.Output); }
private List <Variable> InternalCallConstFunction(IEnumerable <CompleteVariableType> returnTypes, string scAddress, string abi, string functionName, params Variable[] parameters) { TransactionInfo = new TransactionData() { To = scAddress, Function = functionName, Parameters = GetParameterListFormatted(parameters) }; ABIVariableInfo = new BigVariableData() { BaseName = string.Format("abi{0}", functionName), RemainingString = abi, SplitCounter = 0, VariableNames = new List <string>(), NextFunction = CallConstFunctionCommand }; ConsoleOutput output = Execute(SetABIBigVariableCommand(new ConsoleOutput() { Success = true, Output = "Start" })); if (!output.Ok) { throw new Web3Exception(string.Format("Error on call const function.\n\n{0}", output.Output)); } List <Variable> variablesReturned = new List <Variable>(); if (returnTypes.Count() > 1) { IEnumerable <string> values = output.Output.Trim('[', ']').Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(c => c.Trim()); if (values.Count() != returnTypes.Count()) { throw new Web3Exception("Return types do not match."); } for (int i = 0; i < returnTypes.Count(); ++i) { variablesReturned.Add(ParseStringToVariable(values.ElementAt(i), returnTypes.ElementAt(i).Type, returnTypes.ElementAt(i).Decimals)); } } else { variablesReturned.Add(ParseStringToVariable(output.Output, returnTypes.ElementAt(0).Type, returnTypes.ElementAt(0).Decimals)); } return(variablesReturned); }
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', '}', '"')); }