/// <summary>
        /// Parse ContractMethodDescription from json
        /// </summary>
        /// <param name="json">Json</param>
        /// <returns>Return ContractMethodDescription</returns>
        public new static ContractMethodDescriptor FromJson(JObject json)
        {
            ContractMethodDescriptor descriptor = new ContractMethodDescriptor
            {
                Name       = json["name"].AsString(),
                Parameters = ((JArray)json["parameters"]).Select(u => ContractParameterDefinition.FromJson(u)).ToArray(),
                ReturnType = (ContractParameterType)Enum.Parse(typeof(ContractParameterType), json["returntype"].AsString()),
                Offset     = (int)json["offset"].AsNumber(),
                Safe       = json["safe"].AsBoolean(),
            };

            if (string.IsNullOrEmpty(descriptor.Name))
            {
                throw new FormatException();
            }
            _ = descriptor.Parameters.ToDictionary(p => p.Name);
            if (!Enum.IsDefined(descriptor.ReturnType))
            {
                throw new FormatException();
            }
            if (descriptor.Offset < 0)
            {
                throw new FormatException();
            }
            return(descriptor);
        }
Example #2
0
 /// <summary>
 /// Parse ContractMethodDescription from json
 /// </summary>
 /// <param name="json">Json</param>
 /// <returns>Return ContractMethodDescription</returns>
 public static ContractMethodDescriptor FromJson(JObject json)
 {
     return(new ContractMethodDescriptor
     {
         Name = json["name"].AsString(),
         Parameters = ((JArray)json["parameters"]).Select(u => ContractParameterDefinition.FromJson(u)).ToArray(),
     });
 }
 /// <summary>
 /// Parse ContractMethodDescription from json
 /// </summary>
 /// <param name="json">Json</param>
 /// <returns>Return ContractMethodDescription</returns>
 public new static ContractMethodDescriptor FromJson(JObject json)
 {
     return(new ContractMethodDescriptor
     {
         Name = json["name"].AsString(),
         Parameters = ((JArray)json["parameters"]).Select(u => ContractParameterDefinition.FromJson(u)).ToArray(),
         ReturnType = (ContractParameterType)Enum.Parse(typeof(ContractParameterType), json["returnType"].AsString()),
     });
 }
        /// <summary>
        /// Converts the event from a JSON object.
        /// </summary>
        /// <param name="json">The event represented by a JSON object.</param>
        /// <returns>The converted event.</returns>
        public static ContractEventDescriptor FromJson(JObject json)
        {
            ContractEventDescriptor descriptor = new()
            {
                Name       = json["name"].GetString(),
                Parameters = ((JArray)json["parameters"]).Select(u => ContractParameterDefinition.FromJson((JObject)u)).ToArray(),
            };

            if (string.IsNullOrEmpty(descriptor.Name))
            {
                throw new FormatException();
            }
            _ = descriptor.Parameters.ToDictionary(p => p.Name);
            return(descriptor);
        }
Example #5
0
        /// <summary>
        /// Parse ContractParameterDefinition from json
        /// </summary>
        /// <param name="json">Json</param>
        /// <returns>Return ContractParameterDefinition</returns>
        public static ContractParameterDefinition FromJson(JObject json)
        {
            ContractParameterDefinition parameter = new ContractParameterDefinition
            {
                Name = json["name"].AsString(),
                Type = (ContractParameterType)Enum.Parse(typeof(ContractParameterType), json["type"].AsString()),
            };

            if (string.IsNullOrEmpty(parameter.Name))
            {
                throw new FormatException();
            }
            if (!Enum.IsDefined(parameter.Type) || parameter.Type == ContractParameterType.Void)
            {
                throw new FormatException();
            }
            return(parameter);
        }