示例#1
0
 /// <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()),
     });
 }
示例#2
0
        /// <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);
        }
示例#3
0
        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))
            };
        }