コード例 #1
0
        public byte[] Encode(params dynamic[] values)
        {
            MemoryStream stream = new MemoryStream();

            if (values.Length == this._definition.inputs.Length)
            {
                try
                {
                    AbiInputParameter[] parameters = new AbiInputParameter[values.Length];
                    for (int index = 0; index < values.Length; index++)
                    {
                        parameters[index] = new AbiInputParameter(this._definition.inputs[index], values[index]);
                    }
                    stream.Append(this._definition.Sha3Signature);
                    stream.Append(AbiParameterCoder.EncodeParames(parameters));
                }
                catch
                {
                    throw new ArgumentException("input values invalid");
                }
            }
            else
            {
                throw new ArgumentException("values number not match");
            }
            return(stream.ToArray());
        }
コード例 #2
0
        private byte[][] Encode(Dictionary <string, dynamic> args)
        {
            List <byte[]> topics = new List <byte[]>();

            if (!this._definition.Anonymous)
            {
                topics.Add(this._definition.Sha3Signature);
            }

            foreach (var input in this._definition.inputs)
            {
                if (!input.Indexed)
                {
                    continue;
                }
                if (args.ContainsKey(input.Name) && args[input.Name] == null)
                {
                    topics.Add(null);
                }
                else
                {
                    var arg = args[input.Name];
                    if (this.IsDynamicType(input.ABIType))
                    {
                        if (input.ABIType == "string")
                        {
                            byte[] topic = Keccack256.CalculateHash(arg.ToString());
                            topics.Add(topic);
                        }
                        else
                        {
                            if ((arg is string) && (arg as string).IsHexString())
                            {
                                byte[] topic = Keccack256.CalculateHash(arg);
                                topics.Add(topic);
                            }
                            else
                            {
                                throw new ArgumentException(string.Format("invalid {0} value", input.ABIType));
                            }
                        }
                    }
                    else
                    {
                        byte[] topic = AbiParameterCoder.EncodeParame(new AbiInputParameter(input, arg));
                        topics.Add(topic);
                    }
                }
            }
            return(topics.ToArray());
        }
コード例 #3
0
        public byte[] EncodeConstructorWithParameter(params dynamic[] values)
        {
            if (this._definition.Constructor == null)
            {
                throw new ArgumentException("Constructor havn’t parameter");
            }

            List <AbiInputParameter> parameters = new List <AbiInputParameter>();

            for (int index = 0; index < values.Length; index++)
            {
                IAbiParameterDefinition parameDefinition = this._definition.Constructor.inputs[0];
                parameters.Add(new AbiInputParameter(parameDefinition, values[index]));
            }

            return(AbiParameterCoder.EncodeParames(parameters.ToArray()));
        }
コード例 #4
0
 public AbiOutputParameter[] Decode(byte[] outputdata)
 {
     return(AbiParameterCoder.DecodeParames(this._definition.outputs, outputdata));
 }
コード例 #5
0
 public static AbiOutputParameter[] DecodeParames(IAbiParameterDefinition[] parameters, byte[] data)
 {
     return(AbiParameterCoder.Decode(parameters, data));
 }
コード例 #6
0
 public static AbiOutputParameter DecodeParame(IAbiParameterDefinition definition, byte[] data)
 {
     AbiOutputParameter[] outputs = AbiParameterCoder.Decode(new[] { definition }, data);
     return(outputs.Length > 0 ? outputs[0] : null);
 }
コード例 #7
0
 public static byte[] EncodeParames(AbiInputParameter[] parameters)
 {
     return(AbiParameterCoder.Encode(parameters));
 }
コード例 #8
0
 public static byte[] EncodeParame(AbiInputParameter parameter)
 {
     return(AbiParameterCoder.Encode(new[] { parameter }));
 }