Skip to content

Commit fb3967a

Browse files
committed
Updated to the new calling form of decodeHex and decodeHexIfPresent
1 parent a73132d commit fb3967a

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

Sources/web3swift/Transaction/EIP1559Envelope.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ extension EIP1559Envelope {
9494
guard container.contains(.v), container.contains(.r), container.contains(.s) else { return nil }
9595

9696
// everything we need is present, so we should only have to throw from here
97-
self.internalChainID = try container.decodeHexIfPresent(to: BigUInt.self, key: .chainId) ?? 0
98-
self.nonce = try container.decodeHex(to: BigUInt.self, key: .nonce)
97+
self.internalChainID = try container.decodeHexIfPresent(BigUInt.self, forKey: .chainId) ?? 0
98+
self.nonce = try container.decodeHex(BigUInt.self, forKey: .nonce)
9999

100100
let list = try? container.decode([AccessListEntry].self, forKey: .accessList)
101101
self.accessList = list ?? []
@@ -111,15 +111,15 @@ extension EIP1559Envelope {
111111
// swiftlint:enable force_unwrapping
112112
self.to = ethAddr
113113
}
114-
self.value = try container.decodeHexIfPresent(to: BigUInt.self, key: .value) ?? 0
115-
self.maxPriorityFeePerGas = try container.decodeHexIfPresent(to: BigUInt.self, key: .maxPriorityFeePerGas) ?? 0
116-
self.maxFeePerGas = try container.decodeHexIfPresent(to: BigUInt.self, key: .maxFeePerGas) ?? 0
117-
self.gasLimit = try container.decodeHexIfPresent(to: BigUInt.self, key: .gas) ?? container.decodeHexIfPresent(to: BigUInt.self, key: .gasLimit) ?? 0
114+
self.value = try container.decodeHexIfPresent(BigUInt.self, forKey: .value) ?? 0
115+
self.maxPriorityFeePerGas = try container.decodeHexIfPresent(BigUInt.self, forKey: .maxPriorityFeePerGas) ?? 0
116+
self.maxFeePerGas = try container.decodeHexIfPresent(BigUInt.self, forKey: .maxFeePerGas) ?? 0
117+
self.gasLimit = try container.decodeHexIfPresent(BigUInt.self, forKey: .gas) ?? container.decodeHexIfPresent(BigUInt.self, forKey: .gasLimit) ?? 0
118118

119-
self.data = try container.decodeHexIfPresent(to: Data.self, key: .input) ?? container.decodeHex(to: Data.self, key: .data)
120-
self.v = try container.decodeHex(to: BigUInt.self, key: .v)
121-
self.r = try container.decodeHex(to: BigUInt.self, key: .r)
122-
self.s = try container.decodeHex(to: BigUInt.self, key: .s)
119+
self.data = try container.decodeHexIfPresent(Data.self, forKey: .input) ?? container.decodeHex(Data.self, forKey: .data)
120+
self.v = try container.decodeHex(BigUInt.self, forKey: .v)
121+
self.r = try container.decodeHex(BigUInt.self, forKey: .r)
122+
self.s = try container.decodeHex(BigUInt.self, forKey: .s)
123123
}
124124

125125
private enum RlpKey: Int, CaseIterable {

Sources/web3swift/Transaction/EIP2930Envelope.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ extension EIP2930Envelope {
7777
guard container.contains(.v), container.contains(.r), container.contains(.s) else { return nil }
7878

7979
// everything we need is present, so we should only have to throw from here
80-
self.internalChainID = try container.decodeHexIfPresent(to: BigUInt.self, key: .chainId) ?? 0
81-
self.nonce = try container.decodeHex(to: BigUInt.self, key: .nonce)
80+
self.internalChainID = try container.decodeHexIfPresent(BigUInt.self, forKey: .chainId) ?? 0
81+
self.nonce = try container.decodeHex(BigUInt.self, forKey: .nonce)
8282

8383
let list = try? container.decode([AccessListEntry].self, forKey: .accessList)
8484
self.accessList = list ?? []
@@ -94,14 +94,14 @@ extension EIP2930Envelope {
9494
// swiftlint:enable force_unwrapping
9595
self.to = ethAddr
9696
}
97-
self.value = try container.decodeHexIfPresent(to: BigUInt.self, key: .value) ?? 0
98-
self.gasPrice = try container.decodeHexIfPresent(to: BigUInt.self, key: .gasPrice) ?? 0
99-
self.gasLimit = try container.decodeHexIfPresent(to: BigUInt.self, key: .gas) ?? container.decodeHexIfPresent(to: BigUInt.self, key: .gasLimit) ?? 0
100-
101-
self.data = try container.decodeHexIfPresent(to: Data.self, key: .input) ?? container.decodeHex(to: Data.self, key: .data)
102-
self.v = try container.decodeHex(to: BigUInt.self, key: .v)
103-
self.r = try container.decodeHex(to: BigUInt.self, key: .r)
104-
self.s = try container.decodeHex(to: BigUInt.self, key: .s)
97+
self.value = try container.decodeHexIfPresent(BigUInt.self, forKey: .value) ?? 0
98+
self.gasPrice = try container.decodeHexIfPresent(BigUInt.self, forKey: .gasPrice) ?? 0
99+
self.gasLimit = try container.decodeHexIfPresent(BigUInt.self, forKey: .gas) ?? container.decodeHexIfPresent(BigUInt.self, forKey: .gasLimit) ?? 0
100+
101+
self.data = try container.decodeHexIfPresent(Data.self, forKey: .input) ?? container.decodeHex(Data.self, forKey: .data)
102+
self.v = try container.decodeHex(BigUInt.self, forKey: .v)
103+
self.r = try container.decodeHex(BigUInt.self, forKey: .r)
104+
self.s = try container.decodeHex(BigUInt.self, forKey: .s)
105105
}
106106

107107
// RLP encoding positions

Sources/web3swift/Transaction/EnvelopeFactory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public struct EnvelopeFactory {
5151

5252
let envelopeType: TransactionType
5353
if container.contains(.type) {
54-
let typeUInt = try container.decodeHex(to: UInt.self, key: .type)
54+
let typeUInt = try container.decodeHex(UInt.self, forKey: .type)
5555
if typeUInt < TransactionType.total.rawValue {
5656
guard let type = TransactionType(rawValue: typeUInt) else { throw Web3Error.dataError } // conversion error
5757
envelopeType = type

Sources/web3swift/Transaction/LegacyEnvelope.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ extension LegacyEnvelope {
8383
guard container.contains(.v), container.contains(.r), container.contains(.s) else { return nil }
8484

8585
// everything we need is present, so we should only have to throw from here
86-
self.explicitChainID = try container.decodeHexIfPresent(to: BigUInt.self, key: .chainId)
87-
self.nonce = try container.decodeHex(to: BigUInt.self, key: .nonce)
86+
self.explicitChainID = try container.decodeHexIfPresent(BigUInt.self, forKey: .chainId)
87+
self.nonce = try container.decodeHex(BigUInt.self, forKey: .nonce)
8888

8989
let toString = try? container.decode(String.self, forKey: .to)
9090
switch toString {
@@ -97,14 +97,14 @@ extension LegacyEnvelope {
9797
// swiftlint:enable force_unwrapping
9898
self.to = ethAddr
9999
}
100-
self.value = try container.decodeHexIfPresent(to: BigUInt.self, key: .value) ?? 0
101-
self.gasPrice = try container.decodeHexIfPresent(to: BigUInt.self, key: .gasPrice) ?? 0
102-
self.gasLimit = try container.decodeHexIfPresent(to: BigUInt.self, key: .gas) ?? container.decodeHexIfPresent(to: BigUInt.self, key: .gasLimit) ?? 0
100+
self.value = try container.decodeHexIfPresent(BigUInt.self, forKey: .value) ?? 0
101+
self.gasPrice = try container.decodeHexIfPresent(BigUInt.self, forKey: .gasPrice) ?? 0
102+
self.gasLimit = try container.decodeHexIfPresent(BigUInt.self, forKey: .gas) ?? container.decodeHexIfPresent(BigUInt.self, forKey: .gasLimit) ?? 0
103103

104-
self.data = try container.decodeHexIfPresent(to: Data.self, key: .input) ?? container.decodeHex(to: Data.self, key: .data)
105-
self.v = try container.decodeHex(to: BigUInt.self, key: .v)
106-
self.r = try container.decodeHex(to: BigUInt.self, key: .r)
107-
self.s = try container.decodeHex(to: BigUInt.self, key: .s)
104+
self.data = try container.decodeHexIfPresent(Data.self, forKey: .input) ?? container.decodeHex(Data.self, forKey: .data)
105+
self.v = try container.decodeHex(BigUInt.self, forKey: .v)
106+
self.r = try container.decodeHex(BigUInt.self, forKey: .r)
107+
self.s = try container.decodeHex(BigUInt.self, forKey: .s)
108108
}
109109

110110
private enum RlpKey: Int, CaseIterable {

Sources/web3swift/Web3/Web3+Options.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ extension TransactionOptions: Decodable {
210210
let defaultOptions = TransactionOptions.defaultOptions
211211

212212
// type is guaranteed to be set after this
213-
if let typeUInt = try? container.decodeHex(to: UInt.self, key: .type) {
213+
if let typeUInt = try? container.decodeHex(UInt.self, forKey: .type) {
214214
if typeUInt < TransactionType.total.rawValue {
215215
guard let type = TransactionType(rawValue: typeUInt) else { throw Web3Error.dataError }
216216
self.type = type
@@ -231,43 +231,43 @@ extension TransactionOptions: Decodable {
231231

232232
self.from = try container.decodeIfPresent(EthereumAddress.self, forKey: .to)
233233

234-
if let gasPrice = try? container.decodeHex(to: BigUInt.self, key: .gasPrice) {
234+
if let gasPrice = try? container.decodeHex(BigUInt.self, forKey: .gasPrice) {
235235
self.gasPrice = .manual(gasPrice)
236236
} else {
237237
self.gasPrice = defaultOptions.gasPrice
238238
}
239239

240-
if let gasLimit = try? container.decodeHex(to: BigUInt.self, key: .gas) {
240+
if let gasLimit = try? container.decodeHex(BigUInt.self, forKey: .gas) {
241241
self.gasLimit = .manual(gasLimit)
242242
} else {
243243
self.gasLimit = defaultOptions.gasLimit
244244
}
245245

246-
if let maxFeePerGas = try? container.decodeHex(to: BigUInt.self, key: .maxFeePerGas) {
246+
if let maxFeePerGas = try? container.decodeHex(BigUInt.self, forKey: .maxFeePerGas) {
247247
self.maxFeePerGas = .manual(maxFeePerGas)
248248
} else {
249249
self.maxFeePerGas = defaultOptions.maxFeePerGas
250250
}
251251

252-
if let maxPriorityFeePerGas = try? container.decodeHex(to: BigUInt.self, key: .maxPriorityFeePerGas) {
252+
if let maxPriorityFeePerGas = try? container.decodeHex(BigUInt.self, forKey: .maxPriorityFeePerGas) {
253253
self.maxPriorityFeePerGas = .manual(maxPriorityFeePerGas)
254254
} else {
255255
self.maxPriorityFeePerGas = defaultOptions.maxPriorityFeePerGas
256256
}
257257

258-
if let value = try? container.decodeHex(to: BigUInt.self, key: .value) {
258+
if let value = try? container.decodeHex(BigUInt.self, forKey: .value) {
259259
self.value = value
260260
} else {
261261
self.value = defaultOptions.value
262262
}
263263

264-
if let nonce = try? container.decodeHex(to: BigUInt.self, key: .nonce) {
264+
if let nonce = try? container.decodeHex(BigUInt.self, forKey: .nonce) {
265265
self.nonce = .manual(nonce)
266266
} else {
267267
self.nonce = defaultOptions.nonce
268268
}
269269

270-
if let callOnBlock = try? container.decodeHex(to: BigUInt.self, key: .callOnBlock) {
270+
if let callOnBlock = try? container.decodeHex(BigUInt.self, forKey: .callOnBlock) {
271271
self.callOnBlock = .exactBlockNumber(callOnBlock)
272272
} else {
273273
self.callOnBlock = defaultOptions.callOnBlock

0 commit comments

Comments
 (0)