Skip to content

Commit 546a307

Browse files
chore: Block's optional totalDifficulty parsing refactoring;
1 parent 8c68165 commit 546a307

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sources/Web3Core/Structure/Block/Block.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ extension Block: Decodable {
8585
}
8686

8787
self.difficulty = try container.decodeHex(BigUInt.self, forKey: .difficulty)
88-
self.totalDifficulty = (try? container.decodeHex(BigUInt.self, forKey: .totalDifficulty)) ?? .zero
88+
if (container.contains(.totalDifficulty)) {
89+
// Must throw if value is set but it is invalid
90+
self.totalDifficulty = try container.decodeHex(BigUInt.self, forKey: .totalDifficulty)
91+
} else {
92+
self.totalDifficulty = .zero
93+
}
8994
self.extraData = try container.decodeHex(Data.self, forKey: .extraData)
9095
self.size = try container.decodeHex(BigUInt.self, forKey: .size)
9196
self.gasLimit = try container.decodeHex(BigUInt.self, forKey: .gasLimit)

0 commit comments

Comments
 (0)