MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / rlp_encode

Function rlp_encode

utils/src/crypto.rs:248–269  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

246/// The RlP crate panics if stream.out() is invoked when the stream hasn't
247/// consumed all list items (`list_size`).
248pub 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)]
272mod tests {

Callers 1

it_rlp_encodesFunction · 0.85

Calls

no outgoing calls

Tested by 1

it_rlp_encodesFunction · 0.68