Skip to content

Commit 7fd2043

Browse files
committed
bugfix: if let makes no sense if the input won't produce an optional
As it was it would throw a decode error instead of returning nil this was exposed when I fixed the coding key for callOnBlock, which typically isn't present
1 parent b6000e9 commit 7fd2043

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/web3swift/Web3/Web3+Structures.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ extension TransactionOptions: Decodable {
5252

5353
public init(from decoder: Decoder) throws {
5454
let container = try decoder.container(keyedBy: CodingKeys.self)
55-
if let gasLimit = try decodeHexToBigUInt(container, key: .gas) {
55+
if let gasLimit = try decodeHexToBigUInt(container, key: .gas, allowOptional:true) {
5656
self.gasLimit = .manual(gasLimit)
5757
} else {
5858
self.gasLimit = .automatic
5959
}
6060

61-
if let gasPrice = try decodeHexToBigUInt(container, key: .gasPrice) {
61+
if let gasPrice = try decodeHexToBigUInt(container, key: .gasPrice, allowOptional:true) {
6262
self.gasPrice = .manual(gasPrice)
6363
} else {
6464
self.gasPrice = .automatic
@@ -85,13 +85,13 @@ extension TransactionOptions: Decodable {
8585
let value = try decodeHexToBigUInt(container, key: .value)
8686
self.value = value
8787

88-
if let nonce = try decodeHexToBigUInt(container, key: .nonce) {
88+
if let nonce = try decodeHexToBigUInt(container, key: .nonce, allowOptional:true) {
8989
self.nonce = .manual(nonce)
9090
} else {
9191
self.nonce = .pending
9292
}
9393

94-
if let callOnBlock = try decodeHexToBigUInt(container, key: .callOnBlock) {
94+
if let callOnBlock = try decodeHexToBigUInt(container, key: .callOnBlock, allowOptional:true) {
9595
self.callOnBlock = .exactBlockNumber(callOnBlock)
9696
} else {
9797
self.callOnBlock = .pending

0 commit comments

Comments
 (0)