Skip to content

Commit bcebcb0

Browse files
committed
cleanup
1 parent d9fd03c commit bcebcb0

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

Sources/Core/Transaction/CodableTransaction.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,18 @@ public struct CodableTransaction {
188188
return self.envelope.encode(for: type)
189189
}
190190

191-
public mutating func resolve(provider: Web3Provider) async {
191+
public mutating func resolve(provider: Web3Provider) async throws {
192192
// FIXME: Delete force try
193-
self.gasLimit = try! await self.gasLimitPolicy.resolve(provider: provider, transaction: self)
193+
self.gasLimit = try await self.gasLimitPolicy.resolve(provider: provider, transaction: self)
194194

195195
if from != nil || sender != nil {
196-
self.nonce = try! await self.resolveNonce(provider: provider)
196+
self.nonce = try await self.resolveNonce(provider: provider)
197197
}
198198
if case .eip1559 = type {
199-
self.maxFeePerGas = try! await self.maxFeePerGasPolicy.resolve(provider: provider)
200-
self.maxPriorityFeePerGas = try! await self.maxPriorityFeePerGasPolicy.resolve(provider: provider)
199+
self.maxFeePerGas = try await self.maxFeePerGasPolicy.resolve(provider: provider)
200+
self.maxPriorityFeePerGas = try await self.maxPriorityFeePerGasPolicy.resolve(provider: provider)
201201
} else {
202-
self.gasPrice = try! await self.gasPricePolicy.resolve(provider: provider)
202+
self.gasPrice = try await self.gasPricePolicy.resolve(provider: provider)
203203
}
204204
}
205205

@@ -380,12 +380,6 @@ extension CodableTransaction {
380380
return value
381381
}
382382
}
383-
384-
385-
386-
387-
388-
389383
}
390384

391385

Sources/Core/Transaction/Envelope/EIP1559Envelope.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ extension EIP1559Envelope {
249249
let list = accessList.map { $0.encodeAsList() as AnyObject }
250250

251251
switch type {
252-
case .transaction: fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
253-
case .signature: fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list] as [AnyObject]
252+
case .transaction:
253+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
254+
case .signature:
255+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list] as [AnyObject]
254256
}
255257
guard var result = RLP.encode(fields) else { return nil }
256258
result.insert(UInt8(self.type.rawValue), at: 0)

Sources/Core/Transaction/Envelope/EIP2930Envelope.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ extension EIP2930Envelope {
210210
let list = accessList.map { $0.encodeAsList() as AnyObject }
211211

212212
switch type {
213-
case .transaction: fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
214-
case .signature: fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list] as [AnyObject]
213+
case .transaction:
214+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
215+
case .signature:
216+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list] as [AnyObject]
215217
}
216218
guard var result = RLP.encode(fields) else { return nil }
217219
result.insert(UInt8(self.type.rawValue), at: 0)

Sources/Core/Transaction/Envelope/LegacyEnvelope.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ extension LegacyEnvelope {
194194
public func encode(for type: EncodeType = .transaction) -> Data? {
195195
let fields: [AnyObject]
196196
switch type {
197-
case .transaction: fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value, self.data, v, r, s] as [AnyObject]
197+
case .transaction:
198+
fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value, self.data, v, r, s] as [AnyObject]
198199
case .signature:
199200
if let chainID = self.chainID, chainID != 0 {
200201
fields = [self.nonce, self.gasPrice, self.gasLimit, self.to.addressData, self.value, self.data, chainID, BigUInt(0), BigUInt(0)] as [AnyObject]

Sources/Core/Utility/Utilities.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,18 @@ public struct Utilities {
162162
if bigNumber == 0 {
163163
return "0"
164164
}
165-
let unitDecimals = numberDecimals
166165
var toDecimals = formattingDecimals
167-
if unitDecimals < toDecimals {
168-
toDecimals = unitDecimals
166+
if numberDecimals < toDecimals {
167+
toDecimals = numberDecimals
169168
}
170-
let divisor = BigUInt(10).power(unitDecimals)
169+
let divisor = BigUInt(10).power(numberDecimals)
171170
let (quotient, remainder) = bigNumber.quotientAndRemainder(dividingBy: divisor)
172-
var fullRemainder = String(remainder)
173-
let fullPaddedRemainder = fullRemainder.leftPadding(toLength: unitDecimals, withPad: "0")
171+
var fullRemainder = "\(remainder)"
172+
let fullPaddedRemainder = fullRemainder.leftPadding(toLength: numberDecimals, withPad: "0")
174173
let remainderPadded = fullPaddedRemainder[0..<toDecimals]
175174
if remainderPadded == String(repeating: "0", count: toDecimals) {
176175
if quotient != 0 {
177-
return String(quotient)
176+
return "\(quotient)"
178177
} else if fallbackToScientific {
179178
var firstDigit = 0
180179
for char in fullPaddedRemainder {
@@ -205,9 +204,9 @@ public struct Utilities {
205204
}
206205
}
207206
if (toDecimals == 0) {
208-
return String(quotient)
207+
return "\(quotient)"
209208
}
210-
return String(quotient) + decimalSeparator + remainderPadded
209+
return "\(quotient)" + decimalSeparator + remainderPadded
211210
}
212211

213212
/// Recover the Ethereum address from recoverable secp256k1 signature. Message is first hashed using the "personal hash" protocol.

0 commit comments

Comments
 (0)