dpp/address_funds/serde_helpers/mod.rs
1//! Field-level serde helpers for address-based transition fields.
2//!
3//! These helpers reshape the JSON / wasm Object output of `BTreeMap<PlatformAddress, _>`
4//! and `Option<(PlatformAddress, _)>` fields from an opaque map-of-tuples into a
5//! self-describing array (or single object) of `{ address, nonce?, amount? }` entries.
6//!
7//! Only serde JSON / `platform_value` output is affected — the bincode `Encode` /
8//! `Decode` derives on the parent transitions are independent of serde and remain
9//! unchanged, so consensus binary format and `PlatformSignable` sighash are
10//! intentionally untouched. Same safety argument as the custom-serde change applied
11//! to `AddressFundsFeeStrategyStep`.
12//!
13//! Each helper exposes `pub fn serialize` and `pub fn deserialize` so it can be
14//! attached to a struct field via `#[serde(with = "...")]`.
15//!
16//! Module gating lives on the parent re-export in `address_funds/mod.rs`
17//! (`#[cfg(feature = "json-conversion")]`), so this file does not need its
18//! own inner `#![cfg(...)]` attribute.
19
20use crate::address_funds::PlatformAddress;
21use crate::fee::Credits;
22use crate::serialization::json_safe_fields;
23use serde::{Deserialize, Serialize};
24
25pub mod address_input_map;
26pub mod address_output_map_optional_amount;
27pub mod address_output_map_required_amount;
28pub mod address_output_singular;
29
30/// Wire shape for an output address entry: `{ address, amount }` with required amount.
31/// Shared between the `address_output_map_required_amount` and `address_output_singular`
32/// helpers so the JSON shape stays consistent across plural / singular fields.
33///
34/// `#[json_safe_fields]` auto-applies `json_safe_u64` to the `amount` field so values
35/// above `Number.MAX_SAFE_INTEGER` (2^53 − 1) are stringified in human-readable JSON.
36#[json_safe_fields]
37#[derive(Serialize, Deserialize)]
38pub(crate) struct AddressOutputEntry {
39 pub(crate) address: PlatformAddress,
40 pub(crate) amount: Credits,
41}