You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: decode Cycles from little-endian bytes via TryFrom
`Cycles` was decoded from its little-endian byte representation through an
infallible `From<&Vec<u8>>` impl, which left it with no way to report a
length mismatch to its caller. Replace it with `TryFrom<&[u8]>`.
The two protobuf conversions built on it, `state.queues.v1.Cycles` and
`canister_state_bits.v1.CyclesAccount`, become `TryFrom` impls returning
`ProxyDecodeError::ValueOutOfRange`, so a length mismatch is now reported
like any other proto decoding error. This matches how `NominalCycles` and
`CompoundCycles` already decode in the same crate.
The `try_from_option_field` call sites (`Request::cycles_payment`,
`Response::cycles_refund`, `CallContext::available_cycles`,
`CanisterStateBits::cycles_balance`, `Refund::amount`) need no change: they
already required a `TryFrom` whose error converts into `ProxyDecodeError`
and were satisfied through the blanket impl. The callers that used the
infallible impls directly now propagate the error instead:
`CompoundCycles::real`, `Callback::cycles_sent`, the three `RefundStatus`
fields, and four `CanisterStateBits` fields in `state_layout`.
The encoding is unchanged, so this only affects the decoding failure path.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
0 commit comments