Decode an LSPS0 frame and return the raw payload bytes. Validates that the header matches the LSPS0 message type (37913).
(bytes: &[u8])
| 53 | /// |
| 54 | /// Validates that the header matches the LSPS0 message type (37913). |
| 55 | pub fn decode_frame(bytes: &[u8]) -> Result<&[u8]> { |
| 56 | if bytes.len() < 2 { |
| 57 | return Err(Error::TooShort(bytes.len())); |
| 58 | } |
| 59 | let message_type = u16::from_be_bytes([bytes[0], bytes[1]]); |
| 60 | if message_type != LSPS0_MESSAGE_TYPE { |
| 61 | return Err(Error::InvalidMessageType { |
| 62 | type_: message_type, |
| 63 | }); |
| 64 | } |
| 65 | Ok(&bytes[2..]) |
| 66 | } |
| 67 | |
| 68 | /// Represents a monetary amount as defined in LSPS0.msat. Is converted to a |
| 69 | /// `String` in json messages with a suffix `_msat` or `_sat` and internally |
no outgoing calls