Module diem.testing.miniwallet.app.models
Expand source code
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0
from dataclasses import dataclass, field, asdict, fields
from enum import Enum
from typing import Optional, List, Dict, Any
from .... import offchain, diem_types
import json
@dataclass
class Base:
id: str
@dataclass
class Account(Base):
kyc_data: Optional[offchain.KycDataObject] = field(default=None)
reject_additional_kyc_data_request: Optional[bool] = field(default=False)
disable_background_tasks: Optional[bool] = field(default=False)
def kyc_data_object(self) -> offchain.KycDataObject:
return self.kyc_data if self.kyc_data else offchain.individual_kyc_data() # pyre-ignore
@dataclass
class Subaddress(Base):
account_id: str
subaddress_hex: str
@dataclass
class Event(Base):
account_id: str
type: str
data: str
timestamp: int
@dataclass
class KycSample:
minimum: offchain.KycDataObject
reject: offchain.KycDataObject
soft_match: offchain.KycDataObject
soft_reject: offchain.KycDataObject
@staticmethod
def gen(surname: str) -> "KycSample":
def gen_kyc_data(name: str) -> offchain.KycDataObject:
return offchain.individual_kyc_data(given_name=name, surname=surname)
return KycSample(**{f.name: gen_kyc_data("%s-kyc" % f.name) for f in fields(KycSample)})
def match_kyc_data(self, field: str, kyc: offchain.KycDataObject) -> bool:
subset = asdict(getattr(self, field))
return all(getattr(kyc, k) == v for k, v in subset.items() if v)
def match_any_kyc_data(self, fields: List[str], kyc: offchain.KycDataObject) -> bool:
return any(self.match_kyc_data(f, kyc) for f in fields)
class RefundReason(str, Enum):
invalid_subaddress = "invalid_subaddress"
other = "other"
@staticmethod
def from_diem_type(reason: diem_types.RefundReason) -> "RefundReason":
if isinstance(reason, diem_types.RefundReason__InvalidSubaddress):
return RefundReason.invalid_subaddress
return RefundReason.other
def to_diem_type(self) -> diem_types.RefundReason:
return diem_types.RefundReason__InvalidSubaddress()
@dataclass
class Transaction(Base):
class Status(str, Enum):
completed = "completed"
canceled = "canceled"
pending = "pending"
class Type(str, Enum):
sent_payment = "sent_payment"
received_payment = "received_payment"
deposit = "deposit"
account_id: str
currency: str
amount: int
status: Status
type: Type
cancel_reason: Optional[str] = field(default=None)
payee: Optional[str] = field(default=None)
subaddress_hex: Optional[str] = field(default=None)
reference_id: Optional[str] = field(default=None)
signed_transaction: Optional[str] = field(default=None)
diem_transaction_version: Optional[int] = field(default=None)
refund_diem_txn_version: Optional[int] = field(default=None)
refund_reason: Optional[RefundReason] = field(default=None)
def subaddress(self) -> bytes:
return bytes.fromhex(str(self.subaddress_hex))
def balance_amount(self) -> int:
return -self.amount if self.payee else self.amount
def __str__(self) -> str:
return "Transaction %s" % json.dumps(asdict(self), indent=2)
@dataclass
class PaymentCommand(Base):
account_id: str
reference_id: str
cid: str
is_sender: bool
payment_object: Dict[str, Any]
is_inbound: bool = field(default=False)
is_abort: bool = field(default=False)
is_ready: bool = field(default=False)
process_error: Optional[str] = field(default=None)
def to_offchain_command(self) -> offchain.PaymentCommand:
payment = offchain.from_dict(self.payment_object, offchain.PaymentObject)
return offchain.PaymentCommand(
my_actor_address=payment.sender.address if self.is_sender else payment.receiver.address,
payment=payment,
inbound=self.is_inbound,
cid=self.cid,
)
Classes
class Account (id: str, kyc_data: Optional[KycDataObject] = None, reject_additional_kyc_data_request: Optional[bool] = False, disable_background_tasks: Optional[bool] = False)
-
Account(id: str, kyc_data: Optional[diem.offchain.types.payment_types.KycDataObject] = None, reject_additional_kyc_data_request: Optional[bool] = False, disable_background_tasks: Optional[bool] = False)
Expand source code
@dataclass class Account(Base): kyc_data: Optional[offchain.KycDataObject] = field(default=None) reject_additional_kyc_data_request: Optional[bool] = field(default=False) disable_background_tasks: Optional[bool] = field(default=False) def kyc_data_object(self) -> offchain.KycDataObject: return self.kyc_data if self.kyc_data else offchain.individual_kyc_data() # pyre-ignore
Ancestors
Class variables
var disable_background_tasks : Optional[bool]
var kyc_data : Optional[KycDataObject]
var reject_additional_kyc_data_request : Optional[bool]
Methods
def kyc_data_object(self) ‑> KycDataObject
-
Expand source code
def kyc_data_object(self) -> offchain.KycDataObject: return self.kyc_data if self.kyc_data else offchain.individual_kyc_data() # pyre-ignore
class Base (id: str)
-
Base(id: str)
Expand source code
@dataclass class Base: id: str
Subclasses
Class variables
var id : str
class Event (id: str, account_id: str, type: str, data: str, timestamp: int)
-
Event(id: str, account_id: str, type: str, data: str, timestamp: int)
Expand source code
@dataclass class Event(Base): account_id: str type: str data: str timestamp: int
Ancestors
Class variables
var account_id : str
var data : str
var timestamp : int
var type : str
class KycSample (minimum: KycDataObject, reject: KycDataObject, soft_match: KycDataObject, soft_reject: KycDataObject)
-
KycSample(minimum: diem.offchain.types.payment_types.KycDataObject, reject: diem.offchain.types.payment_types.KycDataObject, soft_match: diem.offchain.types.payment_types.KycDataObject, soft_reject: diem.offchain.types.payment_types.KycDataObject)
Expand source code
@dataclass class KycSample: minimum: offchain.KycDataObject reject: offchain.KycDataObject soft_match: offchain.KycDataObject soft_reject: offchain.KycDataObject @staticmethod def gen(surname: str) -> "KycSample": def gen_kyc_data(name: str) -> offchain.KycDataObject: return offchain.individual_kyc_data(given_name=name, surname=surname) return KycSample(**{f.name: gen_kyc_data("%s-kyc" % f.name) for f in fields(KycSample)}) def match_kyc_data(self, field: str, kyc: offchain.KycDataObject) -> bool: subset = asdict(getattr(self, field)) return all(getattr(kyc, k) == v for k, v in subset.items() if v) def match_any_kyc_data(self, fields: List[str], kyc: offchain.KycDataObject) -> bool: return any(self.match_kyc_data(f, kyc) for f in fields)
Class variables
var minimum : KycDataObject
var reject : KycDataObject
var soft_match : KycDataObject
var soft_reject : KycDataObject
Static methods
def gen(surname: str) ‑> KycSample
-
Expand source code
@staticmethod def gen(surname: str) -> "KycSample": def gen_kyc_data(name: str) -> offchain.KycDataObject: return offchain.individual_kyc_data(given_name=name, surname=surname) return KycSample(**{f.name: gen_kyc_data("%s-kyc" % f.name) for f in fields(KycSample)})
Methods
def match_any_kyc_data(self, fields: List[str], kyc: KycDataObject) ‑> bool
-
Expand source code
def match_any_kyc_data(self, fields: List[str], kyc: offchain.KycDataObject) -> bool: return any(self.match_kyc_data(f, kyc) for f in fields)
def match_kyc_data(self, field: str, kyc: KycDataObject) ‑> bool
-
Expand source code
def match_kyc_data(self, field: str, kyc: offchain.KycDataObject) -> bool: subset = asdict(getattr(self, field)) return all(getattr(kyc, k) == v for k, v in subset.items() if v)
class PaymentCommand (id: str, account_id: str, reference_id: str, cid: str, is_sender: bool, payment_object: Dict[str, Any], is_inbound: bool = False, is_abort: bool = False, is_ready: bool = False, process_error: Optional[str] = None)
-
PaymentCommand(id: str, account_id: str, reference_id: str, cid: str, is_sender: bool, payment_object: Dict[str, Any], is_inbound: bool = False, is_abort: bool = False, is_ready: bool = False, process_error: Optional[str] = None)
Expand source code
@dataclass class PaymentCommand(Base): account_id: str reference_id: str cid: str is_sender: bool payment_object: Dict[str, Any] is_inbound: bool = field(default=False) is_abort: bool = field(default=False) is_ready: bool = field(default=False) process_error: Optional[str] = field(default=None) def to_offchain_command(self) -> offchain.PaymentCommand: payment = offchain.from_dict(self.payment_object, offchain.PaymentObject) return offchain.PaymentCommand( my_actor_address=payment.sender.address if self.is_sender else payment.receiver.address, payment=payment, inbound=self.is_inbound, cid=self.cid, )
Ancestors
Class variables
var account_id : str
var cid : str
var is_abort : bool
var is_inbound : bool
var is_ready : bool
var is_sender : bool
var payment_object : Dict[str, Any]
var process_error : Optional[str]
var reference_id : str
Methods
def to_offchain_command(self) ‑> PaymentCommand
-
Expand source code
def to_offchain_command(self) -> offchain.PaymentCommand: payment = offchain.from_dict(self.payment_object, offchain.PaymentObject) return offchain.PaymentCommand( my_actor_address=payment.sender.address if self.is_sender else payment.receiver.address, payment=payment, inbound=self.is_inbound, cid=self.cid, )
class RefundReason (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Expand source code
class RefundReason(str, Enum): invalid_subaddress = "invalid_subaddress" other = "other" @staticmethod def from_diem_type(reason: diem_types.RefundReason) -> "RefundReason": if isinstance(reason, diem_types.RefundReason__InvalidSubaddress): return RefundReason.invalid_subaddress return RefundReason.other def to_diem_type(self) -> diem_types.RefundReason: return diem_types.RefundReason__InvalidSubaddress()
Ancestors
- builtins.str
- enum.Enum
Class variables
var invalid_subaddress
var other
Static methods
def from_diem_type(reason: RefundReason) ‑> RefundReason
-
Expand source code
@staticmethod def from_diem_type(reason: diem_types.RefundReason) -> "RefundReason": if isinstance(reason, diem_types.RefundReason__InvalidSubaddress): return RefundReason.invalid_subaddress return RefundReason.other
Methods
def to_diem_type(self) ‑> RefundReason
-
Expand source code
def to_diem_type(self) -> diem_types.RefundReason: return diem_types.RefundReason__InvalidSubaddress()
class Subaddress (id: str, account_id: str, subaddress_hex: str)
-
Subaddress(id: str, account_id: str, subaddress_hex: str)
Expand source code
@dataclass class Subaddress(Base): account_id: str subaddress_hex: str
Ancestors
Class variables
var account_id : str
var subaddress_hex : str
class Transaction (id: str, account_id: str, currency: str, amount: int, status: Transaction.Status, type: Transaction.Type, cancel_reason: Optional[str] = None, payee: Optional[str] = None, subaddress_hex: Optional[str] = None, reference_id: Optional[str] = None, signed_transaction: Optional[str] = None, diem_transaction_version: Optional[int] = None, refund_diem_txn_version: Optional[int] = None, refund_reason: Optional[RefundReason] = None)
-
Transaction(id: str, account_id: str, currency: str, amount: int, status: diem.testing.miniwallet.app.models.Transaction.Status, type: diem.testing.miniwallet.app.models.Transaction.Type, cancel_reason: Optional[str] = None, payee: Optional[str] = None, subaddress_hex: Optional[str] = None, reference_id: Optional[str] = None, signed_transaction: Optional[str] = None, diem_transaction_version: Optional[int] = None, refund_diem_txn_version: Optional[int] = None, refund_reason: Optional[diem.testing.miniwallet.app.models.RefundReason] = None)
Expand source code
@dataclass class Transaction(Base): class Status(str, Enum): completed = "completed" canceled = "canceled" pending = "pending" class Type(str, Enum): sent_payment = "sent_payment" received_payment = "received_payment" deposit = "deposit" account_id: str currency: str amount: int status: Status type: Type cancel_reason: Optional[str] = field(default=None) payee: Optional[str] = field(default=None) subaddress_hex: Optional[str] = field(default=None) reference_id: Optional[str] = field(default=None) signed_transaction: Optional[str] = field(default=None) diem_transaction_version: Optional[int] = field(default=None) refund_diem_txn_version: Optional[int] = field(default=None) refund_reason: Optional[RefundReason] = field(default=None) def subaddress(self) -> bytes: return bytes.fromhex(str(self.subaddress_hex)) def balance_amount(self) -> int: return -self.amount if self.payee else self.amount def __str__(self) -> str: return "Transaction %s" % json.dumps(asdict(self), indent=2)
Ancestors
Class variables
var Status
-
An enumeration.
var Type
-
An enumeration.
var account_id : str
var amount : int
var cancel_reason : Optional[str]
var currency : str
var diem_transaction_version : Optional[int]
var payee : Optional[str]
var reference_id : Optional[str]
var refund_diem_txn_version : Optional[int]
var refund_reason : Optional[RefundReason]
var signed_transaction : Optional[str]
var status : Transaction.Status
var subaddress_hex : Optional[str]
var type : Transaction.Type
Methods
def balance_amount(self) ‑> int
-
Expand source code
def balance_amount(self) -> int: return -self.amount if self.payee else self.amount
def subaddress(self) ‑> bytes
-
Expand source code
def subaddress(self) -> bytes: return bytes.fromhex(str(self.subaddress_hex))