Skip to content

Commit

Permalink
Add payment field to BaseExecutableContent with specifics for pay…
Browse files Browse the repository at this point in the history
…ment type (#82)

* Add Payment field to BaseExecutableContent with specifics for payment type

* Rename `PaymentType.stream` to `superfluid` to also support other streaming services

* Revert black reformatting

* import execution-related types

* shorten `Payment` property names

* add `is_stream()` property
  • Loading branch information
MHHukiewitz authored Jan 2, 2024
1 parent ee5343e commit 1f5e910
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 33 deletions.
35 changes: 2 additions & 33 deletions aleph_message/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
import json
from copy import copy
from enum import Enum
from hashlib import sha256
from json import JSONDecodeError
from pathlib import Path
Expand All @@ -19,43 +18,13 @@
from typing_extensions import TypeAlias

from .abstract import BaseContent
from .base import Chain, HashType, MessageType
from .execution.instance import InstanceContent
from .execution.program import ProgramContent
from .execution.base import PaymentType, MachineType, Payment
from .item_hash import ItemHash, ItemType


class Chain(str, Enum):
"""Supported chains"""

AVAX = "AVAX"
BSC = "BSC"
CSDK = "CSDK"
DOT = "DOT"
ETH = "ETH"
NEO = "NEO"
NULS = "NULS"
NULS2 = "NULS2"
SOL = "SOL"
TEZOS = "TEZOS"


class HashType(str, Enum):
"""Supported hash functions"""

sha256 = "sha256"


class MessageType(str, Enum):
"""Message types supported by Aleph"""

post = "POST"
aggregate = "AGGREGATE"
store = "STORE"
program = "PROGRAM"
instance = "INSTANCE"
forget = "FORGET"


class MongodbId(BaseModel):
"""PyAleph returns an internal MongoDB id"""

Expand Down
33 changes: 33 additions & 0 deletions aleph_message/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from enum import Enum


class Chain(str, Enum):
"""Supported chains"""

AVAX = "AVAX"
BSC = "BSC"
CSDK = "CSDK"
DOT = "DOT"
ETH = "ETH"
NEO = "NEO"
NULS = "NULS"
NULS2 = "NULS2"
SOL = "SOL"
TEZOS = "TEZOS"


class HashType(str, Enum):
"""Supported hash functions"""

sha256 = "sha256"


class MessageType(str, Enum):
"""Message types supported by Aleph"""

post = "POST"
aggregate = "AGGREGATE"
store = "STORE"
program = "PROGRAM"
instance = "INSTANCE"
forget = "FORGET"
2 changes: 2 additions & 0 deletions aleph_message/models/execution/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
HostRequirements,
MachineResources,
)
from .base import Payment
from .volume import MachineVolume
from ..abstract import BaseContent, HashableModel

Expand All @@ -29,6 +30,7 @@ class BaseExecutableContent(HashableModel, BaseContent, ABC):
description="Properties of the execution environment"
)
resources: MachineResources = Field(description="System resources required")
payment: Optional[Payment] = Field(description="Payment details for the execution")
requirements: Optional[HostRequirements] = Field(
default=None, description="System properties required"
)
Expand Down
26 changes: 26 additions & 0 deletions aleph_message/models/execution/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from __future__ import annotations

from enum import Enum
from typing import Optional

from ..abstract import HashableModel
from ..base import Chain


class Encoding(str, Enum):
Expand All @@ -17,3 +21,25 @@ class MachineType(str, Enum):

vm_instance = "vm-instance"
vm_function = "vm-function"


class PaymentType(str, Enum):
"""Payment type for a program execution."""

hold = "hold"
superfluid = "superfluid"


class Payment(HashableModel):
"""Payment information for a program execution."""

chain: Chain
"""Which chain to check for funds"""
receiver: Optional[str]
"""Optional alternative address to send tokens to"""
type: PaymentType
"""Whether to pay by holding $ALEPH or by streaming tokens"""

@property
def is_stream(self):
return self.type == PaymentType.superfluid

0 comments on commit 1f5e910

Please sign in to comment.