| 1652 | |
| 1653 | @functools.total_ordering |
| 1654 | class Account(object): |
| 1655 | __slots__ = "id", "name", "state", "wallet", "asset", "orders", |
| 1656 | |
| 1657 | def __init__(self, id=0, name="", state=State.initialized | State.bad, wallet=None, asset=None, orders=None): |
| 1658 | if wallet is None: |
| 1659 | wallet = Balance() |
| 1660 | if orders is None: |
| 1661 | orders = list() |
| 1662 | self.id = id |
| 1663 | self.name = name |
| 1664 | self.state = state |
| 1665 | self.wallet = wallet |
| 1666 | self.asset = asset |
| 1667 | self.orders = orders |
| 1668 | |
| 1669 | # Struct shallow copy |
| 1670 | def copy(self, other): |
| 1671 | self.id = other.id |
| 1672 | self.name = other.name |
| 1673 | self.state = other.state |
| 1674 | self.wallet = other.wallet |
| 1675 | self.asset = other.asset |
| 1676 | self.orders = other.orders |
| 1677 | return self |
| 1678 | |
| 1679 | # Struct deep clone |
| 1680 | def clone(self): |
| 1681 | # Serialize the struct to the FBE stream |
| 1682 | writer = AccountModel(fbe.WriteBuffer()) |
| 1683 | writer.serialize(self) |
| 1684 | |
| 1685 | # Deserialize the struct from the FBE stream |
| 1686 | reader = AccountModel(fbe.ReadBuffer()) |
| 1687 | reader.attach_buffer(writer.buffer) |
| 1688 | return reader.deserialize()[0] |
| 1689 | |
| 1690 | def __eq__(self, other): |
| 1691 | if not isinstance(self, other.__class__): |
| 1692 | return NotImplemented |
| 1693 | if not self.id == other.id: |
| 1694 | return False |
| 1695 | return True |
| 1696 | |
| 1697 | def __lt__(self, other): |
| 1698 | if not isinstance(self, other.__class__): |
| 1699 | return NotImplemented |
| 1700 | if self.id < other.id: |
| 1701 | return True |
| 1702 | if self.id == other.id: |
| 1703 | return False |
| 1704 | return False |
| 1705 | |
| 1706 | @property |
| 1707 | def __key__(self): |
| 1708 | return self.id, |
| 1709 | |
| 1710 | def __hash__(self): |
| 1711 | return hash(self.__key__) |
no outgoing calls
no test coverage detected