Loading poolpay/model/messages/Message.py +14 −0 Changes for poolpay/model/messages/Message.py: 14 added lines, 0 removed lines. Original line number Diff line number Diff line from abc import ABC, abstractmethod from dataclasses import dataclass from typing import Self from uuid import UUID from poolpay.wire.Packet import Packet @dataclass(frozen=True) class Message(ABC): uuid: UUID @abstractmethod def to_packet(self) -> Packet: pass @classmethod @abstractmethod def from_packet(cls, packet: Packet) -> Self: """ Try to decode the given packet into a message. :raises PacketDecodeError: If the given packet can not be decoded as such a message. """ pass poolpay/model/messages/UpdateBalanceMessage.py +16 −1 Changes for poolpay/model/messages/UpdateBalanceMessage.py: 16 added lines, 1 removed line. Original line number Diff line number Diff line import json from dataclasses import dataclass from typing import Self from uuid import UUID from poolpay.model.messages.Message import Message Loading @@ -8,7 +9,6 @@ from poolpay.wire.Packet import Packet @dataclass(frozen=True) class UpdateBalanceMessage(Message): uuid: UUID by_amount_cents: int person_full_name: str Loading @@ -24,3 +24,18 @@ class UpdateBalanceMessage(Message): def __repr__(self) -> str: return json.dumps(self.to_packet()) @classmethod def from_packet(cls, packet: Packet) -> Self: """ Try to decode the given packet as an UpdateBalanceMessage. :raises PacketDecodeError: If the given packet can not be decoded as such a message. """ # TODO Throw error on fail return cls( uuid=UUID(packet["uuid"]), by_amount_cents=packet["action"]["by_amount_cents"], person_full_name=packet["person"]["full_name"], ) Loading
poolpay/model/messages/Message.py +14 −0 Changes for poolpay/model/messages/Message.py: 14 added lines, 0 removed lines. Original line number Diff line number Diff line from abc import ABC, abstractmethod from dataclasses import dataclass from typing import Self from uuid import UUID from poolpay.wire.Packet import Packet @dataclass(frozen=True) class Message(ABC): uuid: UUID @abstractmethod def to_packet(self) -> Packet: pass @classmethod @abstractmethod def from_packet(cls, packet: Packet) -> Self: """ Try to decode the given packet into a message. :raises PacketDecodeError: If the given packet can not be decoded as such a message. """ pass
poolpay/model/messages/UpdateBalanceMessage.py +16 −1 Changes for poolpay/model/messages/UpdateBalanceMessage.py: 16 added lines, 1 removed line. Original line number Diff line number Diff line import json from dataclasses import dataclass from typing import Self from uuid import UUID from poolpay.model.messages.Message import Message Loading @@ -8,7 +9,6 @@ from poolpay.wire.Packet import Packet @dataclass(frozen=True) class UpdateBalanceMessage(Message): uuid: UUID by_amount_cents: int person_full_name: str Loading @@ -24,3 +24,18 @@ class UpdateBalanceMessage(Message): def __repr__(self) -> str: return json.dumps(self.to_packet()) @classmethod def from_packet(cls, packet: Packet) -> Self: """ Try to decode the given packet as an UpdateBalanceMessage. :raises PacketDecodeError: If the given packet can not be decoded as such a message. """ # TODO Throw error on fail return cls( uuid=UUID(packet["uuid"]), by_amount_cents=packet["action"]["by_amount_cents"], person_full_name=packet["person"]["full_name"], )