Skip to content

Commit

Permalink
chore: Block's optional totalDifficulty parsing refactoring;
Browse files Browse the repository at this point in the history
  • Loading branch information
JeneaVranceanu committed Nov 6, 2024
1 parent 8c68165 commit 546a307
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/Web3Core/Structure/Block/Block.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ extension Block: Decodable {
}

self.difficulty = try container.decodeHex(BigUInt.self, forKey: .difficulty)
self.totalDifficulty = (try? container.decodeHex(BigUInt.self, forKey: .totalDifficulty)) ?? .zero
if (container.contains(.totalDifficulty)) {
// Must throw if value is set but it is invalid
self.totalDifficulty = try container.decodeHex(BigUInt.self, forKey: .totalDifficulty)
} else {
self.totalDifficulty = .zero
}
self.extraData = try container.decodeHex(Data.self, forKey: .extraData)
self.size = try container.decodeHex(BigUInt.self, forKey: .size)
self.gasLimit = try container.decodeHex(BigUInt.self, forKey: .gasLimit)
Expand Down

0 comments on commit 546a307

Please sign in to comment.