Esempio n. 1
0
        public static object[] GetParametersHex(string hexString, int parameters, List <System.Type> types)
        {
            var objects = new object[parameters];

            for (int i = 0; i < parameters; i++)
            {
                objects[i] = EthereumAbiUtil.GetParameter(hexString, i, types[i]);
            }

            return(objects);
        }
Esempio n. 2
0
        public static string EncodeEthereumFunctionCall(string funcSig, object[] parameters)
        {
            var keccak = new Sha3Keccak();

            var hash = keccak.CalculateHash(funcSig);

            var encodedFunc = EthereumAbiUtil.FirstFourBytesKeccak(hash);

            foreach (var parameter in parameters)
            {
                if (parameter.GetType().Name == "Int32")
                {
                    encodedFunc += EncodeInt32((Int32)parameter);
                }
            }

            return(EthereumAbiUtil.EncodeAsJSON("0x" + encodedFunc));
        }
Esempio n. 3
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);
        }