/// <summary> /// Parse ContractPermission from json /// </summary> /// <param name="json">Json</param> /// <returns>Return ContractPermission</returns> public static ContractPermission FromJson(JObject json) { return(new ContractPermission { Contract = ContractPermissionDescriptor.FromJson(json["contract"]), Methods = WildcardContainer <string> .FromJson(json["methods"], u => u.AsString()), }); }
/// <summary> /// Parse ContractPermission from json /// </summary> /// <param name="json">Json</param> /// <returns>Return ContractPermission</returns> public static ContractPermission FromJson(JObject json) { ContractPermission permission = new ContractPermission { Contract = ContractPermissionDescriptor.FromJson(json["contract"]), Methods = WildcardContainer <string> .FromJson(json["methods"], u => u.GetString()), }; if (permission.Methods.Any(p => string.IsNullOrEmpty(p))) { throw new FormatException(); } _ = permission.Methods.ToDictionary(p => p); return(permission); }
void IInteroperable.FromStackItem(StackItem stackItem) { Struct @struct = (Struct)stackItem; Contract = @struct[0] switch { Null => ContractPermissionDescriptor.CreateWildcard(), StackItem item => new ContractPermissionDescriptor(item.GetSpan()) }; Methods = @struct[1] switch { Null => WildcardContainer <string> .CreateWildcard(), Array array => WildcardContainer <string> .Create(array.Select(p => p.GetString()).ToArray()), _ => throw new ArgumentException(null, nameof(stackItem)) }; }