Beispiel #1
0
        public static object GetParameter(string hexString, int parameter, System.Type type)
        {
            string hs = hexString.RemoveHexPrefix();

            if (type.Name == "String")
            {
                hs = hs.Substring(64 * parameter, 64);
                hs = EthereumAbiUtil.StripPadding(hs);
                return((String)hs);
            }
            else if (type.Name == "Int32")
            {
                hs = hs.Substring(64 * parameter, 64);
                hs = EthereumAbiUtil.StripPadding(hs);
                return(EthereumAbiUtil.ConvertToInt(hs));
            }
            else if (type.Name.Contains("List"))
            {
                // TODO this array variable actually says where the array parameter
                // starts in bytes, we know its up next for now so just take the next
                // one as a count
                var array = hs.Substring(64 * parameter, 64);
                var count = ConvertToInt(hs.Substring(64 * (parameter + 1), 64));

                var list = new List <String>();

                for (int i = 0; i < count; i++)
                {
                    var str = hs.Substring(64 * (parameter + 2 + i), 64);
                    list.Add(str);
                }

                return(list);
            }

            return(hs);
        }