/// <summary> /// /// </summary> /// <param name="strIN"></param> /// <returns></returns> public static string ParameEncod(List <object> strIN) { string result = ""; Nethereum.ABI.FunctionEncoding.ParametersEncoder p = new Nethereum.ABI.FunctionEncoding.ParametersEncoder(); Nethereum.ABI.Model.Parameter[] paary = new Nethereum.ABI.Model.Parameter[strIN.Count]; object[] datas = new object[strIN.Count]; for (int i = 0; i < strIN.Count; i++) { if (strIN[i].ToString().ToLower().StartsWith("0x") && strIN[i].ToString().Length > 40 && strIN[i].ToString().Length < 64) { paary[i] = new Nethereum.ABI.Model.Parameter("address"); } else if (strIN[i].GetType() == typeof(string)) { paary[i] = new Nethereum.ABI.Model.Parameter("string"); } else { paary[i] = new Nethereum.ABI.Model.Parameter("uint256"); } datas[i] = strIN[i]; } byte[] arrByte = p.EncodeParameters(paary, datas); for (int i = 0; i < arrByte.Length; i++) { result += BitConverter.ToString(arrByte, i, 1); } return(result); }
public static byte[] Pack(ContractABI abi, string funcName, object[] args, bool sm) { if (sm) { Nethereum.ABI.FunctionEncoding.ParametersEncoder pe = new Nethereum.ABI.FunctionEncoding.ParametersEncoder(); if (string.IsNullOrEmpty(funcName)) { return(pe.EncodeParameters(abi.Constructor.InputParameters, args)); } else { byte[] arguments = null, id = null; foreach (var item in abi.Functions) { if (item.Name == funcName) { id = GetMethodId(item); arguments = pe.EncodeParameters(item.InputParameters, args); } } byte[] hash = new byte[arguments.Length + id.Length]; Array.Copy(id, 0, hash, 0, id.Length); Array.Copy(arguments, 0, hash, id.Length, arguments.Length); return(hash); } } else { Nethereum.ABI.FunctionEncoding.ParametersEncoder pe = new Nethereum.ABI.FunctionEncoding.ParametersEncoder(); if (string.IsNullOrEmpty(funcName)) { return(pe.EncodeParameters(abi.Constructor.InputParameters, args)); } else { byte[] arguments = null, id = null; foreach (var item in abi.Functions) { if (item.Name == funcName) { id = Hex.Decode(item.Sha3Signature); arguments = pe.EncodeParameters(item.InputParameters, args); } } byte[] hash = new byte[arguments.Length + id.Length]; Array.Copy(id, 0, hash, 0, id.Length); Array.Copy(arguments, 0, hash, id.Length, arguments.Length); return(hash); } } }