subscription - Infernet Client
Description: Infernet Client Documentation

Skip to content

# Module: `subscription`

## `Subscription`

Infernet Coordinator subscription representation

Public methods
Public attributes

serialized (dict[str, Any]): Serialized subscription data. owner (str): Subscription owner + recipient

Private attributes

_active_at (int): Timestamp when subscription is first active _period (int): Time, in seconds, between each subscription interval _frequency (int): Number of times a subscription is processed _redundancy (int): Number of unique nodes that can fulfill each interval _containers_hash (str): Hash of container IDs, this is keccack256 hash of comma-separated container IDs _lazy (bool): Lazy flag _verifier (str): Verifier address _payment_amount (int): Payment amount _payment_token (str): Payment token address _wallet (str): Wallet address of the subscription owner, where payments are made from

Source code in `src/infernet_client/chain/subscription.py`

     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    class Subscription:
        """Infernet Coordinator subscription representation

        Public methods:
            get_delegate_subscription_typed_data: Generates EIP-712 DelegateeSubscription
                data

        Public attributes:
            serialized (dict[str, Any]): Serialized subscription data.
            owner (str): Subscription owner + recipient

        Private attributes:
            _active_at (int): Timestamp when subscription is first active
            _period (int): Time, in seconds, between each subscription interval
            _frequency (int): Number of times a subscription is processed
            _redundancy (int): Number of unique nodes that can fulfill each interval
            _containers_hash (str): Hash of container IDs, this is keccack256 hash of
                comma-separated container IDs
            _lazy (bool): Lazy flag
            _verifier (str): Verifier address
            _payment_amount (int): Payment amount
            _payment_token (str): Payment token address
            _wallet (str): Wallet address of the subscription owner, where payments are
                made from
        """

        def __init__(
            self,
            owner: str,
            active_at: int,
            period: int,
            frequency: int,
            redundancy: int,
            containers: List[str],
            lazy: bool,
            verifier: str,
            payment_amount: int,
            payment_token: str,
            wallet: str,
        ) -> None:
            """Initializes new Subscription

            Args:
                owner (str): Subscription owner + recipient
                active_at (int): Timestamp when subscription is first active
                period (int): Time, in seconds, between each subscription interval
                frequency (int): Number of times a subscription is processed
                redundancy (int): Number of unique nodes that can fulfill each interval
                containers (List[str]): List of container IDs
                lazy (bool): Lazy flag
                verifier (str): Verifier address
                payment_amount (int): Payment amount
                payment_token (str): Payment token address
                wallet (str): Wallet address of the subscription owner
            """

            self.owner = owner
            self._active_at = active_at
            self._period = period
            self._frequency = frequency
            self._redundancy = redundancy
            self._containers_hash = Web3.keccak(
                encode(["string"], [",".join(containers)])
            ).hex()
            self._lazy = lazy
            self._verifier = verifier
            self._payment_amount = payment_amount
            self._payment_token = payment_token
            self._wallet = wallet

        @property
        def serialized(self) -> dict[str, Any]:
            """Returns serialized subscription data.

            Returns:
                dict[str, Any]: Serialized subscription data
            """
            return {
                "owner": self.owner,
                "active_at": self._active_at,
                "period": self._period,
                "frequency": self._frequency,
                "redundancy": self._redundancy,
                "containers": self._containers_hash,
                "lazy": self._lazy,
                "verifier": self._verifier,
                "payment_amount": self._payment_amount,
                "payment_token": self._payment_token,
                "wallet": self._wallet,
            }

        def get_delegate_subscription_typed_data(
            self,
            nonce: int,
            expiry: int,
            chain_id: int,
            verifying_contract: ChecksumAddress,
        ) -> SignableMessage:
            """Generates EIP-712 typed data to sign for DelegateeSubscription

            Args:
                nonce (int): Delegatee signer nonce (relative to owner contract)
                expiry (int): Signature expiry
                chain_id (int): Contract chain ID (non-replayable across chains)
                verifying_contract (ChecksumAddress): EIP-712 signature verifying contract

            Returns:
                SignableMessage: Typed, signable DelegateSubscription message
            """
            return encode_typed_data(
                full_message={
                    "types": {
                        "EIP712Domain": [
                            {"name": "name", "type": "string"},
                            {"name": "version", "type": "string"},
                            {"name": "chainId", "type": "uint256"},
                            {"name": "verifyingContract", "type": "address"},
                        ],
                        "DelegateSubscription": [
                            {"name": "nonce", "type": "uint32"},
                            {"name": "expiry", "type": "uint32"},
                            {"name": "sub", "type": "Subscription"},
                        ],
                        "Subscription": [
                            {"name": "owner", "type": "address"},
                            {"name": "activeAt", "type": "uint32"},
                            {"name": "period", "type": "uint32"},
                            {"name": "frequency", "type": "uint32"},
                            {"name": "redundancy", "type": "uint16"},
                            {"name": "containerId", "type": "bytes32"},
                            {"name": "lazy", "type": "bool"},
                            {"name": "verifier", "type": "address"},
                            {"name": "paymentAmount", "type": "uint256"},
                            {"name": "paymentToken", "type": "address"},
                            {"name": "wallet", "type": "address"},
                        ],
                    },
                    "primaryType": "DelegateSubscription",
                    "domain": {
                        "name": "InfernetCoordinator",
                        "version": "1",
                        "chainId": chain_id,
                        "verifyingContract": verifying_contract,
                    },
                    "message": {
                        "nonce": nonce,
                        "expiry": expiry,
                        "sub": {
                            "owner": self.owner,
                            "activeAt": self._active_at,
                            "period": self._period,
                            "frequency": self._frequency,
                            "redundancy": self._redundancy,
                            "containerId": HexBytes(self._containers_hash),
                            "lazy": self._lazy,
                            "verifier": self._verifier,
                            "paymentAmount": self._payment_amount,
                            "paymentToken": self._payment_token,
                            "wallet": self._wallet,
                        },
                    },
                }
            )

### `serialized: dict[str, Any]` `property`

Returns serialized subscription data.

Returns:

Type | Description
--- | ---
`dict[str, Any]` | dict[str, Any]: Serialized subscription data

### `__init__(owner, active_at, period, frequency, redundancy, containers, lazy, verifier, payment_amount, payment_token, wallet)`

Initializes new Subscription

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`owner` | `str` | Subscription owner + recipient | required
`active_at` | `int` | Timestamp when subscription is first active | required
`period` | `int` | Time, in seconds, between each subscription interval | required
`frequency` | `int` | Number of times a subscription is processed | required
`redundancy` | `int` | Number of unique nodes that can fulfill each interval | required
`containers` | `List[str]` | List of container IDs | required
`lazy` | `bool` | Lazy flag | required
`verifier` | `str` | Verifier address | required
`payment_amount` | `int` | Payment amount | required
`payment_token` | `str` | Payment token address | required
`wallet` | `str` | Wallet address of the subscription owner | required

Source code in `src/infernet_client/chain/subscription.py`

    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    def __init__(
        self,
        owner: str,
        active_at: int,
        period: int,
        frequency: int,
        redundancy: int,
        containers: List[str],
        lazy: bool,
        verifier: str,
        payment_amount: int,
        payment_token: str,
        wallet: str,
    ) -> None:
        """Initializes new Subscription

        Args:
            owner (str): Subscription owner + recipient
            active_at (int): Timestamp when subscription is first active
            period (int): Time, in seconds, between each subscription interval
            frequency (int): Number of times a subscription is processed
            redundancy (int): Number of unique nodes that can fulfill each interval
            containers (List[str]): List of container IDs
            lazy (bool): Lazy flag
            verifier (str): Verifier address
            payment_amount (int): Payment amount
            payment_token (str): Payment token address
            wallet (str): Wallet address of the subscription owner
        """

        self.owner = owner
        self._active_at = active_at
        self._period = period
        self._frequency = frequency
        self._redundancy = redundancy
        self._containers_hash = Web3.keccak(
            encode(["string"], [",".join(containers)])
        ).hex()
        self._lazy = lazy
        self._verifier = verifier
        self._payment_amount = payment_amount
        self._payment_token = payment_token
        self._wallet = wallet

### `get_delegate_subscription_typed_data(nonce, expiry, chain_id, verifying_contract)`

Generates EIP-712 typed data to sign for DelegateeSubscription

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`nonce` | `int` | Delegatee signer nonce (relative to owner contract) | required
`expiry` | `int` | Signature expiry | required
`chain_id` | `int` | Contract chain ID (non-replayable across chains) | required
`verifying_contract` | `ChecksumAddress` | EIP-712 signature verifying contract | required

Returns:

Name | Type | Description
--- | --- | ---
`SignableMessage` | `SignableMessage` | Typed, signable DelegateSubscription message

Source code in `src/infernet_client/chain/subscription.py`

    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    def get_delegate_subscription_typed_data(
        self,
        nonce: int,
        expiry: int,
        chain_id: int,
        verifying_contract: ChecksumAddress,
    ) -> SignableMessage:
        """Generates EIP-712 typed data to sign for DelegateeSubscription

        Args:
            nonce (int): Delegatee signer nonce (relative to owner contract)
            expiry (int): Signature expiry
            chain_id (int): Contract chain ID (non-replayable across chains)
            verifying_contract (ChecksumAddress): EIP-712 signature verifying contract

        Returns:
            SignableMessage: Typed, signable DelegateSubscription message
        """
        return encode_typed_data(
            full_message={
                "types": {
                    "EIP712Domain": [
                        {"name": "name", "type": "string"},
                        {"name": "version", "type": "string"},
                        {"name": "chainId", "type": "uint256"},
                        {"name": "verifyingContract", "type": "address"},
                    ],
                    "DelegateSubscription": [
                        {"name": "nonce", "type": "uint32"},
                        {"name": "expiry", "type": "uint32"},
                        {"name": "sub", "type": "Subscription"},
                    ],
                    "Subscription": [
                        {"name": "owner", "type": "address"},
                        {"name": "activeAt", "type": "uint32"},
                        {"name": "period", "type": "uint32"},
                        {"name": "frequency", "type": "uint32"},
                        {"name": "redundancy", "type": "uint16"},
                        {"name": "containerId", "type": "bytes32"},
                        {"name": "lazy", "type": "bool"},
                        {"name": "verifier", "type": "address"},
                        {"name": "paymentAmount", "type": "uint256"},
                        {"name": "paymentToken", "type": "address"},
                        {"name": "wallet", "type": "address"},
                    ],
                },
                "primaryType": "DelegateSubscription",
                "domain": {
                    "name": "InfernetCoordinator",
                    "version": "1",
                    "chainId": chain_id,
                    "verifyingContract": verifying_contract,
                },
                "message": {
                    "nonce": nonce,
                    "expiry": expiry,
                    "sub": {
                        "owner": self.owner,
                        "activeAt": self._active_at,
                        "period": self._period,
                        "frequency": self._frequency,
                        "redundancy": self._redundancy,
                        "containerId": HexBytes(self._containers_hash),
                        "lazy": self._lazy,
                        "verifier": self._verifier,
                        "paymentAmount": self._payment_amount,
                        "paymentToken": self._payment_token,
                        "wallet": self._wallet,
                    },
                },
            }
        )