/// <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);
        }
Esempio n. 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()),
     });
 }
Esempio n. 4
0
        /// <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);
        }