Module ttd

Source
Expand description

Serde functions for encoding the TTD using a Geth compatible format.

In Go big.Int is marshalled as a JSON number without quotes. Numbers are arbitrary precision in JSON, so this is valid JSON.

These functions serialize the TTD as a JSON number, if the value fits within u128.

The TTD is parsed from:

  • JSON numbers: direct u64 values, or the specific Ethereum mainnet TTD (e.g., 5.875e22 if represented as a float). Other floats or negative numbers will error.
  • JSON strings: these are parsed as U256 (allowing hex or decimal strings).

For non-human-readable formats, the default serde behavior for Option<U256> is used.

Functionsยง

deserialize
Deserializes an optional TTD value from JSON number or string.
deserialize_json_ttd_opt
Supports parsing the TTD as an Option<u64>, or Option<f64> specifically for the mainnet TTD (5.875e22).
serialize
Serializes an optional TTD as a JSON number.