Skip to content

Commit

Permalink
Remove some redundancies
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian-S-A-W committed Apr 30, 2024
1 parent 76bc74b commit a4b79ea
Showing 1 changed file with 15 additions and 39 deletions.
54 changes: 15 additions & 39 deletions Sources/Core/Transaction/EthereumTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -390,54 +390,30 @@ public struct EthereumSignedTransaction {
recId = v.quantity
}
}
let rlp = RLPItem(
nonce: nonce,
gasPrice: gasPrice,
gasLimit: gasLimit,
to: to,
value: value,
data: data,
v: chainId,
r: 0,
s: 0
)
if let _ = try? EthereumPublicKey(message: RLPEncoder().encode(rlp), v: EthereumQuantity(quantity: recId), r: r, s: s) {
return true
do {
let messageToSign = try self.unsignedTransaction().messageToSign(chainId: self.chainId)
if let _ = try? EthereumPublicKey(message: messageToSign, v: EthereumQuantity(quantity: recId), r: r, s: s) {
return true
}
} catch {
return false
}

return false
}

private func verifyEip1559Signature() -> Bool {
let rlp = RLPItem(
nonce: nonce,
gasPrice: gasPrice,
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: maxPriorityFeePerGas,
gasLimit: gasLimit,
to: to,
value: value,
data: data,
v: 0,
r: 0,
s: 0,
chainId: chainId,
accessList: accessList,
transactionType: transactionType
)
var messageToSign = Bytes()
messageToSign.append(0x02)
do {
try messageToSign.append(contentsOf: RLPEncoder().encode(rlp))
let messageToSign = try self.unsignedTransaction().messageToSign(chainId: self.chainId)

if let _ = try? EthereumPublicKey(message: messageToSign, v: v, r: r, s: s) {
return true
}

return false
} catch {
return false
}

if let _ = try? EthereumPublicKey(message: messageToSign, v: v, r: r, s: s) {
return true
}

return false
}

// MARK: - Errors
Expand All @@ -462,7 +438,7 @@ extension EthereumSignedTransaction {
rawTxBytes.removeFirst()
}
do {
var rlp = try RLPDecoder().decode(rawTxBytes)
let rlp = try RLPDecoder().decode(rawTxBytes)

try self.init(rlp: rlp)
} catch {
Expand Down

0 comments on commit a4b79ea

Please sign in to comment.