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

Method write_block

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

Source from the content-addressed store, hash-verified

50 }
51
52 fn write_block(db: &mut Database<BKey>, block: &Block) {
53 let header_ser = serialize(&(block.header));
54 let mut hash_u: [u8; 32] = [0; 32];
55 hash_u8(&header_ser, &mut hash_u);
56
57 let key = BKey{ val: U256::from(hash_u) };
58 let val = serialize(&block);
59 BlockChainDb::write_db(db, key, &val);
60 }
61
62 fn write_tail(mut db: &mut Database<BKey>, block: &Block) {
63 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