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)") + } } }