Exemplo n.º 1
0
        public static List <DecodedContainer> DecodIntoContainer(List <SolidityVar> variableList, Web3 connect,
                                                                 string address, BigInteger index, int offset = 0, string className = "")
        {
            List <DecodedContainer> decodeList = new List <DecodedContainer>();

            for (int i = 0; i < variableList.Count; i++)
            {
                SolidityVar var = variableList[i];
                var         currentContainer = var.DecodeIntoContainer(connect, address, index, offset);
                currentContainer.key = i.ToString();
                decodeList.Add(currentContainer);
                if (i + 1 < variableList.Count)
                {
                    SolidityVar next = variableList[i + 1];
                    if (var.getByteSize() > -1 && next.getByteSize() > -1 && (offset + var.getByteSize() + next.getByteSize() < 32))
                    {
                        offset += var.getByteSize();
                    }
                    else
                    {
                        index += var.getIndexSize();
                        offset = 0;
                    }
                }
            }
            return(decodeList);
        }
Exemplo n.º 2
0
        public static List <DecodedContainer> DecodIntoContainerInstances(SolidityVar var, Web3 connect, string address, int numInstances, BigInteger index, int offset = 0)
        {
            List <DecodedContainer> decodeList = new List <DecodedContainer>();

            for (int i = 0; i < numInstances; i++)
            {
                ethGlobal.DebugPrint(String.Format("[{0}]", i));
                var currContainer = var.DecodeIntoContainer(connect, address, index, offset);
                currContainer.key = i.ToString();
                decodeList.Add(currContainer);
                if (i + 1 < numInstances)
                {
                    SolidityVar next = var;
                    if (!(next is SolidityStruct) && next.getByteSize() > -1 && (offset + var.getByteSize() + next.getByteSize() < 32))
                    {
                        offset += var.getByteSize();
                    }
                    else
                    {
                        index += var.getIndexSize();
                        offset = 0;
                    }
                }
            }
            return(decodeList);
        }
Exemplo n.º 3
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);
        }