public override string GenerateSignature(string name, Parameter[] parameters)
 {
     var signature = new StringBuilder();
     signature.Append(name);
     signature.Append(" ");
     signature.Append(string.Join("", parameters.OrderBy(x => x.Order).Select(x => x.SerpentSignature)));
     return signature.ToString();
 }
Example #2
0
 public virtual string GenerateSignature(string name, Parameter[] parameters)
 {
     var signature = new StringBuilder();
     signature.Append(name);
     signature.Append("(");
     var paramNames = string.Join(",", parameters.OrderBy(x => x.Order).Select(x => x.Type));
     signature.Append(paramNames);
     signature.Append(")");
     return signature.ToString();
 }
Example #3
0
        public Parameter[] BuildFunctionParameters(dynamic inputs)
        {
            var parameters = new List<Parameter>();
            var parameterOrder = 0;
            foreach (dynamic input in inputs)
            {
                parameterOrder = parameterOrder + 1;
                var parameter = new Parameter(input.type, input.name, parameterOrder);
                parameters.Add(parameter);
            }

            return parameters.ToArray();
        }
Example #4
0
        public Parameter[] BuildFunctionParameters(List<object> inputs)
        {
            var parameters = new List<Parameter>();
            var parameterOrder = 0;
            foreach (IDictionary<string, object> input in inputs)
            {
                parameterOrder = parameterOrder + 1;
                var parameter = new Parameter((string) input["type"], (string) input["name"], parameterOrder,
                    TryGetSignatureValue(input));
                parameters.Add(parameter);
            }

            return parameters.ToArray();
        }
Example #5
0
        public byte[] EncodeParameters(Parameter[] parameters, params object[] values)
        {

            if (values.Length > parameters.Length)
            {
                throw new Exception("Too many arguments: " + values.Length + " > " + parameters.Length);
            }

            int staticSize = 0;
            int dynamicCount = 0;
            // calculating static size and number of dynamic params
            for (int i = 0; i < values.Length; i++)
            {
                var parameter = parameters[i];
                int parameterSize = parameter.ABIType.FixedSize;
                if (parameterSize < 0)
                {
                    dynamicCount++;
                    staticSize += 32;
                }
                else
                {
                    staticSize += parameterSize;
                }
            }

            byte[][] encodedBytes = new byte[values.Length + dynamicCount][];

            int currentDynamicPointer = staticSize;
            int currentDynamicCount = 0;
            for (int i = 0; i < values.Length; i++)
            {
                if (parameters[i].ABIType.IsDynamic())
                {
                    byte[] dynamicValueBytes = parameters[i].ABIType.Encode(values[i]);
                    encodedBytes[i] = intTypeEncoder.EncodeInt(currentDynamicPointer);
                    encodedBytes[values.Length + currentDynamicCount] = dynamicValueBytes;
                    currentDynamicCount++;
                    currentDynamicPointer += dynamicValueBytes.Length;
                }
                else
                {
                    encodedBytes[i] = parameters[i].ABIType.Encode(values[i]);
                }
            }
            return ByteUtil.Merge(encodedBytes);

        }
Example #6
0
        public byte[] EncodeParameters(Parameter[] parameters, params object[] values)
        {
            if(values == null && parameters.Length > 0)
                throw new ArgumentNullException(nameof(values), "No values specified for encoding");

            if (values == null) return new byte[] {};

            if (values.Length > parameters.Length)
                throw new Exception("Too many arguments: " + values.Length + " > " + parameters.Length);

            var staticSize = 0;
            var dynamicCount = 0;
            // calculating static size and number of dynamic params
            for (var i = 0; i < values.Length; i++)
            {
                var parameter = parameters[i];
                var parameterSize = parameter.ABIType.FixedSize;
                if (parameterSize < 0)
                {
                    dynamicCount++;
                    staticSize += 32;
                }
                else
                {
                    staticSize += parameterSize;
                }
            }

            var encodedBytes = new byte[values.Length + dynamicCount][];

            var currentDynamicPointer = staticSize;
            var currentDynamicCount = 0;
            for (var i = 0; i < values.Length; i++)
                if (parameters[i].ABIType.IsDynamic())
                {
                    var dynamicValueBytes = parameters[i].ABIType.Encode(values[i]);
                    encodedBytes[i] = intTypeEncoder.EncodeInt(currentDynamicPointer);
                    encodedBytes[values.Length + currentDynamicCount] = dynamicValueBytes;
                    currentDynamicCount++;
                    currentDynamicPointer += dynamicValueBytes.Length;
                }
                else
                {
                    encodedBytes[i] = parameters[i].ABIType.Encode(values[i]);
                }
            return ByteUtil.Merge(encodedBytes);
        }
Example #7
0
 public string GenerateSha3Signature(string name, Parameter[] parameters, int numberOfFirstBytes)
 {
     return GenerateSha3Signature(name, parameters).Substring(0, numberOfFirstBytes*2);
 }
Example #8
0
 public string GenerateSha3Signature(string name, Parameter[] parameters)
 {
     var signature = GenerateSignature(name, parameters);
     return sha3Keccack.CalculateHash(signature);
 }
Example #9
0
        public Parameter[] BuildEventParameters(List<object> inputs)
        {
            var parameters = new List<Parameter>();
            var parameterOrder = 0;
            foreach (IDictionary<string, object> input in inputs)
            {
                parameterOrder = parameterOrder + 1;
                var parameter = new Parameter((string) input["type"], (string) input["name"], parameterOrder)
                {
                    Indexed = (bool) input["indexed"]
                };
                parameters.Add(parameter);
            }

            return parameters.ToArray();
        }
Example #10
0
        public Parameter[] BuildEventParameters(dynamic inputs)
        {
            var parameters = new List<Parameter>();
            var parameterOrder = 0;
            foreach (dynamic input in inputs)
            {
                parameterOrder = parameterOrder + 1;
                var parameter = new Parameter(input.type, input.name, parameterOrder) {Indexed = input.indexed};
                parameters.Add(parameter);
            }

            return parameters.ToArray();
        }