Exemplo n.º 1
0
        public override DecodedContainer DecodeIntoContainer(Web3 web, string address, BigInteger index, int offset)
        {
            string           val  = getStorageAt(web, address, index);
            DecodedContainer cont = new DecodedContainer
            {
                rawValue    = val,
                solidityVar = this
            };

            cont.children.AddRange(solidtyDecoder.DecodIntoContainer(typesList, web, address, index, offset));
            return(cont);
        }
Exemplo n.º 2
0
        public override DecodedContainer DecodeIntoContainer(Web3 web, string address, BigInteger index, int offset)
        {
            if (offset > 0)
            {
                throw new NotSupportedException("Error the array should not have an offset");
            }
            string val = getStorageAt(web, address, index);
            //this is the lenth
            int len = Convert.ToInt32(val, 16);

            ethGlobal.DebugPrint("Decoding Arrray " + name + " with length " + len);
            List <string> res = new List <string>();
            //res.Add("(array)" + name + "=");

            String str    = index.ToString("x64");
            var    newkey = new Sha3Keccack().CalculateHashFromHex(str);//pad with zero to prevent BigIntegar prase from making number negative

            ethGlobal.DebugPrint("Array Decoding index  " + str + " hash is " + newkey);
            //var newkey = Web3.Sha3((index).ToString());//pad with zero to prevent BigIntegar prase from making number negative
            BigInteger       ind  = BigInteger.Parse("0" + newkey, System.Globalization.NumberStyles.HexNumber);//pad with zero to prevent BigIntegar prase from making number negative
            DecodedContainer cont = new DecodedContainer
            {
                rawValue    = val,
                solidityVar = this
            };

            /*for (int i = 0; i < len; i++)
             * {
             *  // var newkey = new Sha3Keccack().CalculateHash((i).ToString());
             *  //BigInteger ind = new BigInteger(Encoding.ASCII.GetBytes(newkey));
             *  var chld = basevar.DecodeIntoContainer(web, address, ind + (i * basevar.getIndexSize()),0);
             *  chld.key = i.ToString();
             *  cont.children.Add(chld);
             * }*/
            cont.children.AddRange(solidtyDecoder.DecodIntoContainerInstances(basevar, web, address, len, ind, offset));
            return(cont);
        }
Exemplo n.º 3
0
        /*
         * vn1 = "somethting"
         * vn2 = 0x1200
         * map
         *   [key1] struct demo1
         *      array
         *         [0]
         *         [1]
         *     uint a =b
         *     uint c= 3
         *   [key2] */

        public static StringBuilder printDecoded(DecodedContainer cont, int depth, int spacesize = 3)
        {
            StringBuilder current    = new StringBuilder();
            string        keytext    = "";
            string        spc        = "";
            string        name       = cont.solidityVar.name;
            string        decoded    = " " + cont.decodedValue;
            string        structline = "";
            int           depthinc   = 1;

            if (!String.IsNullOrEmpty(cont.key))
            {
                keytext = String.Format("[{0}]", cont.key);
                if (!(cont.solidityVar is SolidityArray || cont.solidityVar is SolidityMap | depth == 0))
                {
                    name = "";
                }
                if (cont.solidityVar is SolidityStruct)
                {
                    structline = pad(spacesize * (depth + 1)) + cont.solidityVar.name;
                    depthinc   = 2;
                }
                //decoded = "";
            }
            current.AppendLine(pad(spacesize * depth) + String.Format("{0} {1}{2}", keytext, name, decoded));
            if (!String.IsNullOrEmpty(structline))
            {
                current.AppendLine(structline);
            }

            foreach (var child in cont.children)
            {
                current.Append(printDecoded(child, depth + depthinc, spacesize));
            }
            return(current);
        }
Exemplo n.º 4
0
        public override DecodedContainer DecodeIntoContainer(Web3 web, string address, BigInteger index, int offset)
        {
            if (offset > 0)
            {
                throw new NotSupportedException("Error map does not support offset");
            }
            string           val  = getStorageAt(web, address, index);
            DecodedContainer cont = new DecodedContainer
            {
                rawValue    = val,
                solidityVar = this
            };

            if (KeyDecodeList.Haskeys(name))
            {
                foreach (var ky in KeyDecodeList.GetKeys(name))
                {
                    String str    = (index).ToString("x64");
                    String str2   = ky.ToString("x64");
                    var    newkey = new Sha3Keccack().CalculateHashFromHex(str2, str);

                    BigInteger ind           = BigInteger.Parse("0" + newkey, System.Globalization.NumberStyles.HexNumber);//pad with zero to prevent BigIntegar prase from making number negative
                    var        currContainer = basevar.DecodeIntoContainer(web, address, ind, 0);
                    currContainer.key = ky.ToString();
                    cont.children.Add(currContainer);
                }
            }
            if (MultiKeyDecodeList.Haskeys(name))
            {
                foreach (var ky in MultiKeyDecodeList.GetKeys(name))
                {
                    String[] items = ky.Split(',', StringSplitOptions.RemoveEmptyEntries);
                    if (items.Length != depth)
                    {
                        Console.WriteLine("incorrect number dimensions/depth for decode keys for {0} {1}", name, ky);
                        continue;
                    }
                    String str = (index).ToString("x64");
                    //first key is the index to the map
                    string lastkey = str;
                    ethGlobal.DebugPrint(String.Format("Decoding Map {0} [{1}]", name, ky));
                    foreach (string itm in items)
                    {
                        BigInteger num;
                        if (itm.StartsWith("0x"))
                        {
                            num = BigInteger.Parse(itm.Replace("0x", "0"), System.Globalization.NumberStyles.HexNumber);
                        }
                        else
                        {
                            num = BigInteger.Parse("0" + itm, System.Globalization.NumberStyles.Number);
                        }
                        //allitems.Insert(0, num.ToString("x64"));
                        string oldkey = lastkey;
                        lastkey = new Sha3Keccack().CalculateHashFromHex(num.ToString("x64"), lastkey);
                        ethGlobal.DebugPrint(String.Format("Hash for Map: new Sha3Keccack().CalculateHashFromHex({0}, {1}) {2}",
                                                           num.ToString("x64"), oldkey, lastkey));
                    }
                    //var newkey = Web3.Sha3((index).ToString());//pad with zero to prevent BigIntegar prase from making number negative
                    BigInteger ind = BigInteger.Parse("0" + lastkey, System.Globalization.NumberStyles.HexNumber);//pad with zero to prevent BigIntegar prase from making number negative

                    var currContianer = basevar.DecodeIntoContainer(web, address, ind, 0);
                    currContianer.key = ky;
                    cont.children.Add(currContianer);
                }
            }
            return(cont);
        }