Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payment field to BaseExecutableContent with specifics for payment type #82

Merged
merged 6 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
MHHukiewitz marked this conversation as resolved.
Show resolved Hide resolved
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")
MHHukiewitz marked this conversation as resolved.
Show resolved Hide resolved
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"
MHHukiewitz marked this conversation as resolved.
Show resolved Hide resolved


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

chain: Chain
MHHukiewitz marked this conversation as resolved.
Show resolved Hide resolved
"""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