Generalize `MktPair.from_msg()` handling
Accept a msg with any of: - `.src: Asset` and `.dst: Asset` - `.src: str` and `.dst: str` - `.src: Asset` and `.dst: str` but not the final combo tho XD Also, fix `.key` to properly cast any `.src: Asset` to string!rekt_pps
parent
aa5f25231a
commit
8f79c37b99
|
@ -236,16 +236,31 @@ class MktPair(Struct, frozen=True):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
dst_asset_msg = msg.pop('dst')
|
dst_asset_msg = msg.pop('dst')
|
||||||
|
src_asset_msg = msg.pop('src')
|
||||||
|
|
||||||
if isinstance(dst_asset_msg, str):
|
if isinstance(dst_asset_msg, str):
|
||||||
|
src: str = str(src_asset_msg)
|
||||||
|
assert isinstance(src, str)
|
||||||
return cls.from_fqme(
|
return cls.from_fqme(
|
||||||
dst_asset_msg,
|
dst_asset_msg,
|
||||||
|
src=src,
|
||||||
**msg,
|
**msg,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
# NOTE: we call `.copy()` here to ensure
|
# NOTE: we call `.copy()` here to ensure
|
||||||
# type casting!
|
# type casting!
|
||||||
dst = Asset(**dst_asset_msg).copy()
|
dst = Asset(**dst_asset_msg).copy()
|
||||||
return cls(dst=dst, **msg).copy()
|
if not isinstance(src_asset_msg, str):
|
||||||
|
src = Asset(**src_asset_msg).copy()
|
||||||
|
else:
|
||||||
|
src = str(src_asset_msg)
|
||||||
|
|
||||||
|
return cls(
|
||||||
|
dst=dst,
|
||||||
|
src=src,
|
||||||
|
**msg,
|
||||||
|
).copy()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def resolved(self) -> bool:
|
def resolved(self) -> bool:
|
||||||
|
@ -292,7 +307,8 @@ class MktPair(Struct, frozen=True):
|
||||||
|
|
||||||
'''
|
'''
|
||||||
return maybe_cons_tokens(
|
return maybe_cons_tokens(
|
||||||
[str(self.dst), self.src],
|
[str(self.dst),
|
||||||
|
str(self.src)],
|
||||||
delim_char='',
|
delim_char='',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue