degenbot.utils¶
Utility modules for degenbot.
Submodules¶
Package Contents¶
- degenbot.utils.to_0x_hex(data: bytes | bytearray | str) str¶
Return
0x-prefixed lowercase hex of data (degenbot semantics).bytes/bytearrayare RAW data: re-encoded via.hex()(this is how degenbot has historically derived address, pool-id and tx-hash hex from rawbytes).stris first decoded as hex viato_bytes()(upstreamstr.__str__rule).- Returns:
The hex string with a
0xprefix ("0x"for empty input).
- degenbot.utils.to_bytes(data: BytesLikeSource) bytes¶
Decode a value to
bytesfollowing the old wrapper’s matrix.Conversion matrix (old wrapper
to_bytes, preserved byte-for-byte):bytes– returned as-is (no copy);bytearray– converted tobytes(copied);memoryview– converted (.tobytes());bool– checked beforeint:False->b"\x00",True->b"\x01";int–to_bytes((data.bit_length() + 7) // 8, "big")(the0edge – one zero byte – comes frombit_length, and 256 uses 2 bytes);str–bytes.fromhex(s)after skipping an optional0xprefix, with odd-length hex left-padded (upstream rule); ASCII non-hex chars raisebinascii.Error(aValueErrorsubclass) and non-ASCII characters propagate theUnicodeEncodeError(upstream’sexceptclause catchesUnicodeDecodeError, which.encode()never raises);any other input –
TypeError(kept for values reaching this function through untyped / dynamic callers).
- Returns:
The decoded
bytes.- Raises:
TypeError – If data is not one of the accepted container types.
ValueError – If data is a negative
intor a string containing non-hex characters (binascii.Error).