Encode items in a RlpStream The RlP crate panics if stream.out() is invoked when the stream hasn't consumed all list items (`list_size`).
(items: Vec<T>, signature: Option<&Signature>)
| 246 | /// The RlP crate panics if stream.out() is invoked when the stream hasn't |
| 247 | /// consumed all list items (`list_size`). |
| 248 | pub fn rlp_encode<T: Encodable>(items: Vec<T>, signature: Option<&Signature>) -> RlpStream { |
| 249 | let mut stream = RlpStream::new(); |
| 250 | let mut list_size = items.len(); |
| 251 | |
| 252 | if signature.is_some() { |
| 253 | list_size += 3 |
| 254 | } |
| 255 | |
| 256 | stream.begin_list(list_size); |
| 257 | |
| 258 | items.iter().for_each(|item| { |
| 259 | stream.append(item); |
| 260 | }); |
| 261 | |
| 262 | if let Some(signature) = signature { |
| 263 | stream.append(&signature.v); |
| 264 | stream.append(&U256::from_big_endian(signature.r.as_bytes())); |
| 265 | stream.append(&U256::from_big_endian(signature.s.as_bytes())); |
| 266 | } |
| 267 | |
| 268 | stream |
| 269 | } |
| 270 | |
| 271 | #[cfg(test)] |
| 272 | mod tests { |
no outgoing calls