pub fn apply_balances_iter<T: ListMutTarget<u64>>(
target: &mut T,
delta: &ArchivedBalancesDiff,
)Expand description
Applies a balance delta to a mutable balance collection in place.
target must initially contain the base balance snapshot used to
generate delta.
Existing balances are reconstructed according to the packed tags in the delta. Changed balances encoded as differences are updated relative to their current base value, while explicit and zero-valued entries replace the corresponding balance directly.
Any balances stored in BalancesDiff::appended_balances are appended to
the collection after the common portion has been reconstructed.
This API accepts crate::ListMutTarget so that consensus clients can
apply the delta directly to tree-backed or persistent balance collections
without first materializing them as a Vec<u64>.
§Correctness
The supplied collection must correspond to the base snapshot for which
delta was generated. The delta does not contain enough information to
independently validate the original base balances.
§Complexity
The delta is processed in linear order over the encoded balance entries.
The total cost therefore depends on the complexity of
crate::ListMutTarget::get_mut for the supplied collection.
§Panics
In debug builds, panics if the length of the supplied collection does not match the length represented by the delta’s tag vector.
The function also assumes that the serialized delta is structurally valid. Invalid varint payloads or inconsistent tag/payload data may panic during reconstruction.