Esempio n. 1
0
        public static ContractParameter ToParameter(this StackItem item)
        {
            switch (item)
            {
            case VMArray array:
                return(new ContractParameter
                {
                    Type = ContractParameterType.Array,
                    Value = array.Select(p => p.ToParameter()).ToArray()
                });

            case VMBoolean _:
                return(new ContractParameter
                {
                    Type = ContractParameterType.Boolean,
                    Value = item.GetBoolean()
                });

            case ByteArray _:
                return(new ContractParameter
                {
                    Type = ContractParameterType.ByteArray,
                    Value = item.GetByteArray()
                });

            case Integer _:
                return(new ContractParameter
                {
                    Type = ContractParameterType.Integer,
                    Value = item.GetBigInteger()
                });

            case InteropInterface _:
                return(new ContractParameter
                {
                    Type = ContractParameterType.InteropInterface
                });

            default:
                throw new ArgumentException();
            }
        }
Esempio n. 2
0
        private static ContractParameter ToParameter(StackItem item, List <Tuple <StackItem, ContractParameter> > context)
        {
            ContractParameter parameter = null;

            switch (item)
            {
            case VMArray array:
                if (context is null)
                {
                    context = new List <Tuple <StackItem, ContractParameter> >();
                }
                else
                {
                    parameter = context.FirstOrDefault(p => ReferenceEquals(p.Item1, item))?.Item2;
                }
                if (parameter is null)
                {
                    parameter = new ContractParameter {
                        Type = ContractParameterType.Array
                    };
                    context.Add(new Tuple <StackItem, ContractParameter>(item, parameter));
                    parameter.Value = array.Select(p => ToParameter(p, context)).ToList();
                }
                break;

            case Map map:
                if (context is null)
                {
                    context = new List <Tuple <StackItem, ContractParameter> >();
                }
                else
                {
                    parameter = context.FirstOrDefault(p => ReferenceEquals(p.Item1, item))?.Item2;
                }
                if (parameter is null)
                {
                    parameter = new ContractParameter {
                        Type = ContractParameterType.Map
                    };
                    context.Add(new Tuple <StackItem, ContractParameter>(item, parameter));
                    parameter.Value = map.Select(p => new KeyValuePair <ContractParameter, ContractParameter>(ToParameter(p.Key, context), ToParameter(p.Value, context))).ToList();
                }
                break;

            case VMBoolean _:
                parameter = new ContractParameter
                {
                    Type  = ContractParameterType.Boolean,
                    Value = item.GetBoolean()
                };
                break;

            case ByteArray _:
                parameter = new ContractParameter
                {
                    Type  = ContractParameterType.ByteArray,
                    Value = item.GetByteArray()
                };
                break;

            case Integer _:
                parameter = new ContractParameter
                {
                    Type  = ContractParameterType.Integer,
                    Value = item.GetBigInteger()
                };
                break;

            case InteropInterface _:
                parameter = new ContractParameter
                {
                    Type = ContractParameterType.InteropInterface
                };
                break;

            default:
                throw new ArgumentException();
            }
            return(parameter);
        }