Skip to content

Commit

Permalink
feat: add __hash__ to the xdr classes. (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Aug 24, 2023
1 parent a4ee387 commit bac5ffc
Show file tree
Hide file tree
Showing 342 changed files with 2,704 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ xdr/Stellar-internal.x \
xdr/Stellar-contract-config-setting.x

XDRGEN_REPO=overcat/xdrgen
XDRGEN_COMMIT=3a25689ac881fd9370b45ac2e98908cea86ddaf3
XDRGEN_COMMIT=904ac3c9925902fa892fbfd4883e20b056f71712
XDRNEXT_COMMIT=e372df9f677961aac04c5a4cc80a3667f310b29f

UNAME := $(shell uname)
Expand Down Expand Up @@ -61,6 +61,7 @@ clean:
format:
autoflake --in-place --ignore-init-module-imports --remove-all-unused-imports --recursive .
isort .
black .
.PHONY: format

replace-xdr-keywords:
Expand Down
16 changes: 16 additions & 0 deletions stellar_sdk/xdr/account_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ def from_xdr(cls, xdr: str) -> AccountEntry:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.account_id,
self.balance,
self.seq_num,
self.num_sub_entries,
self.inflation_dest,
self.flags,
self.home_domain,
self.thresholds,
self.signers,
self.ext,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/account_entry_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def from_xdr(cls, xdr: str) -> AccountEntryExt:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.v,
self.v1,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/account_entry_extension_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def from_xdr(cls, xdr: str) -> AccountEntryExtensionV1:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.liabilities,
self.ext,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/account_entry_extension_v1_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def from_xdr(cls, xdr: str) -> AccountEntryExtensionV1Ext:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.v,
self.v2,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
10 changes: 10 additions & 0 deletions stellar_sdk/xdr/account_entry_extension_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ def from_xdr(cls, xdr: str) -> AccountEntryExtensionV2:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.num_sponsored,
self.num_sponsoring,
self.signer_sponsoring_i_ds,
self.ext,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/account_entry_extension_v2_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def from_xdr(cls, xdr: str) -> AccountEntryExtensionV2Ext:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.v,
self.v3,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
9 changes: 9 additions & 0 deletions stellar_sdk/xdr/account_entry_extension_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def from_xdr(cls, xdr: str) -> AccountEntryExtensionV3:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.ext,
self.seq_ledger,
self.seq_time,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
3 changes: 3 additions & 0 deletions stellar_sdk/xdr/account_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def from_xdr(cls, xdr: str) -> AccountID:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(self.account_id)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/account_merge_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ def from_xdr(cls, xdr: str) -> AccountMergeResult:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.code,
self.source_account_balance,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
9 changes: 9 additions & 0 deletions stellar_sdk/xdr/allow_trust_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def from_xdr(cls, xdr: str) -> AllowTrustOp:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.trustor,
self.asset,
self.authorize,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
3 changes: 3 additions & 0 deletions stellar_sdk/xdr/allow_trust_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def from_xdr(cls, xdr: str) -> AllowTrustResult:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash((self.code,))

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/alpha_num12.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def from_xdr(cls, xdr: str) -> AlphaNum12:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.asset_code,
self.issuer,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/alpha_num4.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def from_xdr(cls, xdr: str) -> AlphaNum4:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.asset_code,
self.issuer,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
9 changes: 9 additions & 0 deletions stellar_sdk/xdr/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ def from_xdr(cls, xdr: str) -> Asset:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.type,
self.alpha_num4,
self.alpha_num12,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
9 changes: 9 additions & 0 deletions stellar_sdk/xdr/asset_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def from_xdr(cls, xdr: str) -> AssetCode:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.type,
self.asset_code4,
self.asset_code12,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
3 changes: 3 additions & 0 deletions stellar_sdk/xdr/asset_code12.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def from_xdr(cls, xdr: str) -> AssetCode12:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(self.asset_code12)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
3 changes: 3 additions & 0 deletions stellar_sdk/xdr/asset_code4.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def from_xdr(cls, xdr: str) -> AssetCode4:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(self.asset_code4)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
3 changes: 3 additions & 0 deletions stellar_sdk/xdr/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def from_xdr(cls, xdr: str) -> Auth:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash((self.flags,))

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
9 changes: 9 additions & 0 deletions stellar_sdk/xdr/auth_cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def from_xdr(cls, xdr: str) -> AuthCert:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.pubkey,
self.expiration,
self.sig,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
8 changes: 8 additions & 0 deletions stellar_sdk/xdr/authenticated_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def from_xdr(cls, xdr: str) -> AuthenticatedMessage:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.v,
self.v0,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
9 changes: 9 additions & 0 deletions stellar_sdk/xdr/authenticated_message_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def from_xdr(cls, xdr: str) -> AuthenticatedMessageV0:
xdr_bytes = base64.b64decode(xdr.encode())
return cls.from_xdr_bytes(xdr_bytes)

def __hash__(self):
return hash(
(
self.sequence,
self.message,
self.mac,
)
)

def __eq__(self, other: object):
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
Loading

0 comments on commit bac5ffc

Please sign in to comment.