From 58ed3677eeb3e7a01d6c50586f2502f7c73a609e Mon Sep 17 00:00:00 2001 From: "h33min.kim" Date: Thu, 31 Oct 2024 13:32:19 +0900 Subject: [PATCH 1/5] modified Block struct - modified to allow an optional type of 'totalDifficulty' - because 'totalDifficulty' was removed from Ethereum official Blockschema --- Sources/Web3Core/Structure/Block/Block.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Web3Core/Structure/Block/Block.swift b/Sources/Web3Core/Structure/Block/Block.swift index 1cb587d2e..281df8dbe 100644 --- a/Sources/Web3Core/Structure/Block/Block.swift +++ b/Sources/Web3Core/Structure/Block/Block.swift @@ -24,7 +24,7 @@ public struct Block { public var receiptsRoot: Data public var miner: EthereumAddress? // MARK: This is NOT optional in web3js public var difficulty: BigUInt - public var totalDifficulty: BigUInt + public var totalDifficulty: BigUInt? // MARK by JoshKim: Removed from Ethereum official Blockschema (https://github.com/ethereum/execution-apis/commit/9e16d5e76a554c733613a2db631130166e2d8725) public var extraData: Data public var size: BigUInt public var gasLimit: BigUInt @@ -83,7 +83,7 @@ extension Block: Decodable { } self.difficulty = try container.decodeHex(BigUInt.self, forKey: .difficulty) - self.totalDifficulty = try container.decodeHex(BigUInt.self, forKey: .totalDifficulty) + self.totalDifficulty = try? container.decodeHex(BigUInt.self, forKey: .totalDifficulty) 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) From 329bcb400f64c0fa06420ba803efd1232b256445 Mon Sep 17 00:00:00 2001 From: Heemin Kim <36722822+h33min@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:05:43 +0900 Subject: [PATCH 2/5] Update Sources/Web3Core/Structure/Block/Block.swift Co-authored-by: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> --- Sources/Web3Core/Structure/Block/Block.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Web3Core/Structure/Block/Block.swift b/Sources/Web3Core/Structure/Block/Block.swift index 281df8dbe..6dfdfb967 100644 --- a/Sources/Web3Core/Structure/Block/Block.swift +++ b/Sources/Web3Core/Structure/Block/Block.swift @@ -24,7 +24,9 @@ public struct Block { public var receiptsRoot: Data public var miner: EthereumAddress? // MARK: This is NOT optional in web3js public var difficulty: BigUInt - public var totalDifficulty: BigUInt? // MARK by JoshKim: Removed from Ethereum official Blockschema (https://github.com/ethereum/execution-apis/commit/9e16d5e76a554c733613a2db631130166e2d8725) + /// by JoshKim: Removed from Ethereum official Blockschema making it optional (https://github.com/ethereum/execution-apis/commit/9e16d5e76a554c733613a2db631130166e2d8725) + /// If decoding of this field has failed it will be set to 0 to avoid breaking changes. Will be made optional in v4 of web3swift. + public var totalDifficulty: BigUInt public var extraData: Data public var size: BigUInt public var gasLimit: BigUInt From 8c6816528a33038028c80dd6d6cfa23ed2eb6320 Mon Sep 17 00:00:00 2001 From: Heemin Kim <36722822+h33min@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:05:52 +0900 Subject: [PATCH 3/5] Update Sources/Web3Core/Structure/Block/Block.swift Co-authored-by: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> --- Sources/Web3Core/Structure/Block/Block.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Web3Core/Structure/Block/Block.swift b/Sources/Web3Core/Structure/Block/Block.swift index 6dfdfb967..8752954a3 100644 --- a/Sources/Web3Core/Structure/Block/Block.swift +++ b/Sources/Web3Core/Structure/Block/Block.swift @@ -85,7 +85,7 @@ extension Block: Decodable { } self.difficulty = try container.decodeHex(BigUInt.self, forKey: .difficulty) - self.totalDifficulty = try? container.decodeHex(BigUInt.self, forKey: .totalDifficulty) + self.totalDifficulty = (try? container.decodeHex(BigUInt.self, forKey: .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) From 546a3073f58186380a2013e96729a4b6c63f366e Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu Date: Wed, 6 Nov 2024 17:09:08 +0200 Subject: [PATCH 4/5] chore: Block's optional totalDifficulty parsing refactoring; --- Sources/Web3Core/Structure/Block/Block.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/Web3Core/Structure/Block/Block.swift b/Sources/Web3Core/Structure/Block/Block.swift index 8752954a3..587458bcf 100644 --- a/Sources/Web3Core/Structure/Block/Block.swift +++ b/Sources/Web3Core/Structure/Block/Block.swift @@ -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) From 82d9b1a6a0b1082d65a0deec5e292acce5e00494 Mon Sep 17 00:00:00 2001 From: Jenea Vranceanu <36865532+JeneaVranceanu@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:11:02 +0200 Subject: [PATCH 5/5] chore: swift doc update for the totalDifficulty field; --- Sources/Web3Core/Structure/Block/Block.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Web3Core/Structure/Block/Block.swift b/Sources/Web3Core/Structure/Block/Block.swift index 587458bcf..adfc4466e 100644 --- a/Sources/Web3Core/Structure/Block/Block.swift +++ b/Sources/Web3Core/Structure/Block/Block.swift @@ -25,7 +25,7 @@ public struct Block { public var miner: EthereumAddress? // MARK: This is NOT optional in web3js public var difficulty: BigUInt /// by JoshKim: Removed from Ethereum official Blockschema making it optional (https://github.com/ethereum/execution-apis/commit/9e16d5e76a554c733613a2db631130166e2d8725) - /// If decoding of this field has failed it will be set to 0 to avoid breaking changes. Will be made optional in v4 of web3swift. + /// Set to 0 if not provided. Will be made optional in v4 of web3swift. public var totalDifficulty: BigUInt public var extraData: Data public var size: BigUInt