Пример #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))
            };
        }
Пример #4
0
        void IInteroperable.FromStackItem(StackItem stackItem)
        {
            Struct @struct = (Struct)stackItem;

            Name               = @struct[0].GetString();
            Groups             = ((Array)@struct[1]).Select(p => p.ToInteroperable <ContractGroup>()).ToArray();
            SupportedStandards = ((Array)@struct[2]).Select(p => p.GetString()).ToArray();
            Abi         = @struct[3].ToInteroperable <ContractAbi>();
            Permissions = ((Array)@struct[4]).Select(p => p.ToInteroperable <ContractPermission>()).ToArray();
            Trusts      = @struct[5] switch
            {
                Null => WildcardContainer <UInt160> .CreateWildcard(),
                Array array => WildcardContainer <UInt160> .Create(array.Select(p => new UInt160(p.GetSpan())).ToArray()),
                _ => throw new ArgumentException(null, nameof(stackItem))
            };
            Extra = JObject.Parse(@struct[6].GetSpan());
        }
Пример #5
0
 /// <summary>
 /// Create Default Contract manifest
 /// </summary>
 /// <param name="hash">Hash</param>
 /// <returns>Return default manifest for this contract</returns>
 public static ContractManifest CreateDefault(UInt160 hash)
 {
     return(new ContractManifest()
     {
         Permissions = new[] { ContractPermission.DefaultPermission },
         Abi = new ContractAbi()
         {
             Hash = hash,
             EntryPoint = ContractMethodDescriptor.DefaultEntryPoint,
             Events = new ContractEventDescriptor[0],
             Methods = new ContractMethodDescriptor[0]
         },
         Features = ContractFeatures.NoProperty,
         Groups = new ContractGroup[0],
         SafeMethods = WildcardContainer <string> .Create(),
         Trusts = WildcardContainer <UInt160> .Create(),
         Extra = null,
     });
 }
Пример #6
0
        private void DeserializeFromJson(JObject json)
        {
            Abi         = ContractAbi.FromJson(json["abi"]);
            Groups      = ((JArray)json["groups"]).Select(u => ContractGroup.FromJson(u)).ToArray();
            Features    = ContractFeatures.NoProperty;
            Permissions = ((JArray)json["permissions"]).Select(u => ContractPermission.FromJson(u)).ToArray();
            Trusts      = WildcardContainer <UInt160> .FromJson(json["trusts"], u => UInt160.Parse(u.AsString()));

            SafeMethods = WildcardContainer <string> .FromJson(json["safeMethods"], u => u.AsString());

            Extra = json["extra"];
            if (json["features"]["storage"].AsBoolean())
            {
                Features |= ContractFeatures.HasStorage;
            }
            if (json["features"]["payable"].AsBoolean())
            {
                Features |= ContractFeatures.Payable;
            }
        }
Пример #7
0
        void IInteroperable.FromStackItem(StackItem stackItem)
        {
            Struct @struct = (Struct)stackItem;

            Name   = @struct[0].GetString();
            Groups = ((Array)@struct[1]).Select(p => p.ToInteroperable <ContractGroup>()).ToArray();
            if (((Map)@struct[2]).Count != 0)
            {
                throw new ArgumentException(null, nameof(stackItem));
            }
            SupportedStandards = ((Array)@struct[3]).Select(p => p.GetString()).ToArray();
            Abi         = @struct[4].ToInteroperable <ContractAbi>();
            Permissions = ((Array)@struct[5]).Select(p => p.ToInteroperable <ContractPermission>()).ToArray();
            Trusts      = @struct[6] switch
            {
                Null => WildcardContainer <ContractPermissionDescriptor> .CreateWildcard(),
                Array array => WildcardContainer <ContractPermissionDescriptor> .Create(array.Select(p => new ContractPermissionDescriptor(p.GetSpan())).ToArray()),
                _ => throw new ArgumentException(null, nameof(stackItem))
            };
            Extra = (JObject)JToken.Parse(@struct[7].GetSpan());
        }