/// <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);
        }
Exemple #2
0
 /// <summary>
 /// Parse ContractAbi from json
 /// </summary>
 /// <param name="json">Json</param>
 /// <returns>Return ContractAbi</returns>
 public static ContractAbi FromJson(JObject json)
 {
     return(new ContractAbi
     {
         Methods = ((JArray)json["methods"]).Select(u => ContractMethodDescriptor.FromJson(u)).ToArray(),
         Events = ((JArray)json["events"]).Select(u => ContractEventDescriptor.FromJson(u)).ToArray()
     });
 }
Exemple #3
0
 /// <summary>
 /// Parse ContractAbi from json
 /// </summary>
 /// <param name="json">Json</param>
 /// <returns>Return ContractAbi</returns>
 public static ContractAbi FromJson(JObject json)
 {
     return(new ContractAbi
     {
         Hash = UInt160.Parse(json["hash"].AsString()),
         Methods = ((JArray)json["methods"]).Select(u => ContractMethodDescriptor.FromJson(u)).ToArray(),
         Events = ((JArray)json["events"]).Select(u => ContractEventDescriptor.FromJson(u)).ToArray()
     });
 }