MCPcopy Create free account
hub / github.com/base/base / encode

Method encode

crates/proof/mpt/src/node.rs:516–553  ·  view source on GitHub ↗
(&self, out: &mut dyn alloy_rlp::BufMut)

Source from the content-addressed store, hash-verified

514
515impl Encodable for TrieNode {
516 fn encode(&self, out: &mut dyn alloy_rlp::BufMut) {
517 let payload_length = self.payload_length();
518 match self {
519 Self::Empty => out.put_u8(EMPTY_STRING_CODE),
520 Self::Blinded { commitment } => commitment.encode(out),
521 Self::Leaf { prefix, value } => {
522 // Encode the leaf node's header and key-value pair.
523 Header { list: true, payload_length }.encode(out);
524 alloy_trie::nodes::encode_path_leaf(prefix, true).as_slice().encode(out);
525 value.encode(out);
526 }
527 Self::Extension { prefix, node } => {
528 // Encode the extension node's header, prefix, and pointer node.
529 Header { list: true, payload_length }.encode(out);
530 alloy_trie::nodes::encode_path_leaf(prefix, false).as_slice().encode(out);
531 if node.length() >= B256::ZERO.len() {
532 let hash = node.blind();
533 hash.encode(out);
534 } else {
535 node.encode(out);
536 }
537 }
538 Self::Branch { stack } => {
539 // In branch nodes, if an element is longer than 32 bytes in length, it is blinded.
540 // Assuming we have an open trie node, we must re-hash the elements
541 // that are longer than 32 bytes in length.
542 Header { list: true, payload_length }.encode(out);
543 for node in stack {
544 if node.length() >= B256::ZERO.len() {
545 let hash = node.blind();
546 hash.encode(out);
547 } else {
548 node.encode(out);
549 }
550 }
551 }
552 }
553 }
554
555 fn length(&self) -> usize {
556 match self {

Callers 7

test_list_walkerFunction · 0.45
blindMethod · 0.45
test_decode_branchFunction · 0.45

Calls 4

payload_lengthMethod · 0.80
blindMethod · 0.80
lengthMethod · 0.45
lenMethod · 0.45