MCPcopy Create free account
hub / github.com/ElementsProject/elements / to_jsonable

Function to_jsonable

contrib/message-capture/message-capture-parser.py:73–92  ·  view source on GitHub ↗
(obj: Any)

Source from the content-addressed store, hash-verified

71
72
73def to_jsonable(obj: Any) -> Any:
74 if hasattr(obj, "__dict__"):
75 return obj.__dict__
76 elif hasattr(obj, "__slots__"):
77 ret = {} # type: Any
78 for slot in obj.__slots__:
79 val = getattr(obj, slot, None)
80 if slot in HASH_INTS and isinstance(val, int):
81 ret[slot] = ser_uint256(val).hex()
82 elif slot in HASH_INT_VECTORS and isinstance(val[0], int):
83 ret[slot] = [ser_uint256(a).hex() for a in val]
84 else:
85 ret[slot] = to_jsonable(val)
86 return ret
87 elif isinstance(obj, list):
88 return [to_jsonable(a) for a in obj]
89 elif isinstance(obj, bytes):
90 return obj.hex()
91 else:
92 return obj
93
94
95def process_file(path: str, messages: List[Any], recv: bool, progress_bar: Optional[ProgressBar]) -> None:

Callers 1

process_fileFunction · 0.85

Calls 2

ser_uint256Function · 0.90
hexMethod · 0.80

Tested by

no test coverage detected