Пример #1
0
    def from_json(cls, json: dict) -> ContractMethodDescriptor:
        """
        Parse object out of JSON data.

        Args:
            json: a dictionary.

        Raises:
            KeyError: if the data supplied does not contain the necessary keys.
            ValueError: if the manifest name property has an incorrect format.
            ValueError: if the offset is negative.
        """
        c = cls(name=contracts.validate_type(json['name'], str),
                offset=contracts.validate_type(json['offset'], int),
                parameters=list(
                    map(
                        lambda p: contracts.ContractParameterDefinition.
                        from_json(p), json['parameters'])),
                return_type=contracts.ContractParameterType[
                    contracts.validate_type(json['returntype'], str).upper()],
                safe=contracts.validate_type(json['safe'], bool))
        if c.name is None or len(c.name) == 0:
            raise ValueError("Format error - invalid 'name'")
        if c.offset < 0:
            raise ValueError("Format error - negative offset not allowed")
        return c
Пример #2
0
    def _deserialize_from_json(self, json: dict) -> None:
        if json['name'] is None:
            self.name = ""
        else:
            self.name = contracts.validate_type(json['name'], str)
        self.abi = contracts.ContractABI.from_json(json['abi'])
        self.groups = list(
            map(lambda g: ContractGroup.from_json(g), json['groups']))

        if len(json['features']) != 0:
            raise ValueError(
                "Manifest features is reserved and cannot have any content at this time"
            )

        self.supported_standards = list(
            map(lambda ss: contracts.validate_type(ss, str),
                json['supportedstandards']))
        self.permissions = list(
            map(lambda p: ContractPermission.from_json(p),
                json['permissions']))

        if json['trusts'] == '*':
            self.trusts = WildcardContainer.create_wildcard()
        else:
            self.trusts = WildcardContainer.from_json_as_type(
                {'wildcard': json['trusts']}, lambda t: contracts.
                ContractPermissionDescriptor.from_json({'contract': t}))

        # converting json key/value back to default WildcardContainer format
        self.extra = json['extra']
Пример #3
0
    def _deserialize_from_json(self, json: dict) -> None:
        if json['name'] is None:
            self.name = ""
        else:
            self.name = contracts.validate_type(json['name'], str)
        self.abi = contracts.ContractABI.from_json(json['abi'])
        self.groups = list(map(lambda g: ContractGroup.from_json(g), json['groups']))
        self.supported_standards = list(map(lambda ss: contracts.validate_type(ss, str), json['supportedstandards']))
        self.permissions = list(map(lambda p: ContractPermission.from_json(p), json['permissions']))

        self.trusts = WildcardContainer.from_json_as_type(
            {'wildcard': json['trusts']},
            lambda t: types.UInt160.from_string(contracts.validate_type(t, str)))

        # converting json key/value back to default WildcardContainer format
        self.extra = json['extra']
Пример #4
0
    def from_json(cls, json: dict) -> ContractGroup:
        """
        Parse object out of JSON data.

        Args:
            json: a dictionary.

        Raises:
            KeyError: if the data supplied does not contain the necessary keys.
            ValueError: if the signature length is not 64.
        """
        pubkey = contracts.validate_type(json['pubkey'], str)
        c = cls(
            public_key=cryptography.ECPoint.deserialize_from_bytes(binascii.unhexlify(pubkey)),
            signature=base64.b64decode(contracts.validate_type(json['signature'], str).encode('utf8'))
        )
        if len(c.signature) != 64:
            raise ValueError("Format error - invalid signature length")
        return c
Пример #5
0
    def from_json(cls, json: dict) -> ContractParameterDefinition:
        """
        Parse object out of JSON data.

        Args:
            json: a dictionary.

        Raises:
            KeyError: if the data supplied does not contain the necessary keys.
            ValueError: if the manifest name property has an incorrect format.
            ValueError: if the type is VOID.
        """
        c = cls(name=contracts.validate_type(json['name'], str),
                type=contracts.ContractParameterType[contracts.validate_type(
                    json['type'], str).upper()])
        if c.name is None or len(c.name) == 0:
            raise ValueError("Format error - invalid 'name'")
        if c.type == contracts.ContractParameterType.VOID:
            raise ValueError(
                "Format error - parameter type VOID is not allowed")
        return c
Пример #6
0
    def from_json(cls, json: dict) -> ContractEventDescriptor:
        """
        Parse object out of JSON data.

        Args:
            json: a dictionary.

        Raises:
            KeyError: if the data supplied does not contain the necessary key.
            ValueError: if the 'name' property has an incorrect format
        """
        c = cls(name=contracts.validate_type(json['name'], str),
                parameters=list(
                    map(lambda p: ContractParameterDefinition.from_json(p),
                        json['parameters'])))
        if c.name is None or len(c.name) == 0:
            raise ValueError("Format error - invalid 'name'")
        return c