Encode an operation's immutable payload and verify its derived ID.
(operation: &Operation)
| 16 | |
| 17 | /// Encode an operation's immutable payload and verify its derived ID. |
| 18 | pub fn encode_operation(operation: &Operation) -> Result<Vec<u8>, OperationCodecError> { |
| 19 | let bytes = encode_operation_payload(operation.payload(), operation.encoding_version())?; |
| 20 | let actual = OperationId::from_canonical_bytes(&bytes); |
| 21 | if actual != operation.id() { |
| 22 | return Err(OperationCodecError::new(format!( |
| 23 | "operation ID mismatch: stored {}, computed {}", |
| 24 | operation.id(), |
| 25 | actual |
| 26 | ))); |
| 27 | } |
| 28 | Ok(bytes) |
| 29 | } |
| 30 | |
| 31 | pub(crate) fn encode_operation_payload( |
| 32 | payload: &OperationPayload, |