From 51f5908e0ef06261ba3acb579e132a3d2abf455c Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 17 Jul 2024 13:52:55 +1200 Subject: [PATCH] fix --- Blockchain/Sources/Blockchain/Blockchain.swift | 2 +- Blockchain/Sources/Blockchain/Types/Header.swift | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Blockchain/Sources/Blockchain/Blockchain.swift b/Blockchain/Sources/Blockchain/Blockchain.swift index f0ff385d..2a28dcba 100644 --- a/Blockchain/Sources/Blockchain/Blockchain.swift +++ b/Blockchain/Sources/Blockchain/Blockchain.swift @@ -34,7 +34,7 @@ public class Blockchain { } private func addState(_ state: StateRef) { - stateByBlockHash[state.value.lastBlock.header.hash] = state + stateByBlockHash[state.value.lastBlock.header.hash()] = state stateByTimeslot[state.value.lastBlock.header.timeslotIndex, default: []].append(state) } } diff --git a/Blockchain/Sources/Blockchain/Types/Header.swift b/Blockchain/Sources/Blockchain/Types/Header.swift index e6577ac7..49ae07e3 100644 --- a/Blockchain/Sources/Blockchain/Types/Header.swift +++ b/Blockchain/Sources/Blockchain/Types/Header.swift @@ -119,7 +119,11 @@ extension Header: ScaleCodec.Encodable { } extension Header { - public func hash() throws -> Data32 { - try blake2b256(ScaleCodec.encode(self)) + public func hash() -> Data32 { + do { + return try blake2b256(ScaleCodec.encode(self)) + } catch let e { + fatalError("Failed to hash header: \(e)") + } } }