Skip to content

Commit 9d84b4a

Browse files
committed
refactor to remove force unwraps
1 parent 051f94f commit 9d84b4a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Sources/web3swift/Transaction/EthereumTransaction.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ public struct EthereumTransaction: CustomStringConvertible {
125125
} else if self.v >= 27 && self.v <= 30 {
126126
d = BigUInt(27)
127127
}
128-
if (self.chainID != nil && self.chainID != BigUInt(0) && self.v >= (d + self.chainID! + self.chainID!)) {
129-
normalizedV = self.v - d - self.chainID! - self.chainID!
130-
} else if (inferedChainID != nil && self.v >= (d + self.inferedChainID! + self.inferedChainID!)) {
131-
normalizedV = self.v - d - inferedChainID! - inferedChainID!
128+
if let testID = self.chainID, testID != BigUInt(0) && self.v >= (d + testID + testID) {
129+
normalizedV = self.v - d - testID - testID
130+
} else if let testID = inferedChainID, self.v >= (d + testID + testID) {
131+
normalizedV = self.v - d - testID - testID
132132
} else {
133133
if(d > v) { d = 0 }
134134
normalizedV = self.v - d

Sources/web3swift/Web3/Web3+Structures.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ extension EthereumTransaction:Decodable {
118118
let container = try decoder.container(keyedBy: CodingKeys.self)
119119

120120
// test to see if it is a EIP-1559 wrapper
121-
let envelope = try decodeHexToBigUInt(container, key: .type, allowOptional: true)
122-
if( (envelope != nil) && (envelope! != BigInt(0)) ) {
121+
if let envelope = try decodeHexToBigUInt(container, key: .type, allowOptional: true) {
123122
// if present and non-sero we are a new wrapper we can't decode
124-
throw Web3Error.dataError
123+
if(envelope != BigInt(0)) { throw Web3Error.dataError }
125124
}
126-
125+
127126
var data = try decodeHexToData(container, key: .data, allowOptional: true)
128127
if data != nil {
129128
self.data = data!

0 commit comments

Comments
 (0)