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

Method write_block

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

Source from the content-addressed store, hash-verified

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