thruput-xdr 0.72.0

Bindings for Thruput protocol structures
Documentation
# Types Module

This module contains the core type definitions for the Thruput protocol, including cryptographic primitives, storage types, and fundamental protocol constants.

## Overview

The `types` module provides the foundational types used throughout the Thruput protocol. These types are generated from the XDR specification in `protocol/types.x` and include:

- **Cryptographic types**: Ed25519 and ML-DSA-65 keys and signatures
- **Storage types**: Contract addresses, storage keys, and hashes
- **Protocol primitives**: Time points, gas amounts, block heights

## Contract Addresses

Contract code written with `thruput-sdk` should hold the address of a
contract it calls as `thruput_sdk::Address<C>`. That type names the generated
client, or tuple of clients, used to call the contract, so the interface is
stated once, at the declaration.

If you really need an address untyped, [`ContractAddress`] is the bare
32 bytes: for an address that is never called, such as an owner or a
recipient, for one whose interface is not known, and for code outside a
contract. The two encode identically.

## Time and Height Arithmetic

Arithmetic on [`TimePoint`] with [`TimeSpan`], the length of time between
two timepoints, and on [`BlockHeight`] with a signed number of blocks. All
three are `Copy`.

```
use thruput_xdr::types::{BlockHeight, TimePoint, TimeSpan};

let now = TimePoint::UNIX_EPOCH + TimeSpan::from_secs(1_700_000_000);
let deadline = now + TimeSpan::from_days(7);
assert!(now < deadline);
assert_eq!(deadline - now, TimeSpan::from_hours(7 * 24));
assert_eq!(now.duration_since(deadline), TimeSpan::ZERO);
assert_eq!(now.checked_duration_since(deadline), None);
assert_eq!(format!("{now:?}"), "TimePoint(2023-11-14T22:13:20Z)");
assert_eq!(format!("{:?}", deadline - now), "TimeSpan(604800s)");

let height = BlockHeight::new(1_000);
let expiry = height + 100;
assert_eq!(expiry - height, 100);
```

A `TimeSpan` counts in the unit of `TimePoint` and encodes as a timepoint
does. Build one with [`TimeSpan::from_secs`] and its siblings, so that code
does not depend on the unit. [`TimeSpan::from_duration`] and `Duration::from`
convert from and to [`core::time::Duration`].

Every `+`, `-` and `*` operator on these types checks for overflow in every
build profile and panics when it happens, as `core::time` does and the
integer primitives do not: a deadline that silently wrapped into the past
would be a security bug in a contract. The `checked_*` methods (and, on
`TimePoint`, the `saturating_*` methods) handle the edge without panicking.

Subtracting a later timepoint from an earlier one panics too, rather than
saturating as `std::time::Instant` does. So an age check such as
`now - observed <= max_age` rejects an observation from the future instead
of reading it as fresh. [`TimePoint::duration_since`] is the saturating
form, for the time left before a deadline, and
[`TimePoint::checked_duration_since`] returns `None` when the argument is
later. Subtracting one height from another is a plain signed difference.

`Debug` prints a timepoint as an RFC 3339 UTC timestamp, and a span as
[`core::time::Duration`] prints, rather than as a bare count of the unit.