MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / write_block

Method write_block

code/chapter09/blockchain/blockchain7/core/src/blockchain.rs:77–85  ·  view source on GitHub ↗
(db: &mut Database<BKey>, block: &Block)

Source from the content-addressed store, hash-verified

75 }
76
77 fn write_block(db: &mut Database<BKey>, block: &Block) {
78 let header_ser = serialize(&(block.header));
79 let mut hash_u: [u8; 32] = [0; 32];
80 hash_u8(&header_ser, &mut hash_u);
81
82 let key = BKey{ val: U256::from(hash_u) };
83 let val = serialize(&block);
84 BlockChainDb::write_db(db, key, &val);
85 }
86
87 fn write_tail(mut db: &mut Database<BKey>, block: &Block) {
88 let key = BKey{ val: U256::from("tail".as_bytes()) };

Callers

nothing calls this directly

Calls 2

serializeFunction · 0.50
hash_u8Function · 0.50

Tested by

no test coverage detected