File tree Expand file tree Collapse file tree 3 files changed +8
-11
lines changed
Sources/web3swift/Transaction Expand file tree Collapse file tree 3 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ extension EIP1559Envelope {
122
122
self . s = try container. decodeHex ( to: BigUInt . self, key: . s)
123
123
}
124
124
125
- private enum RlpKey : Int {
125
+ private enum RlpKey : Int , CaseIterable {
126
126
case chainId
127
127
case nonce
128
128
case maxPriorityFeePerGas
@@ -135,17 +135,16 @@ extension EIP1559Envelope {
135
135
case sig_v
136
136
case sig_r
137
137
case sig_s
138
- case total // not a real entry, used to auto-size based on number of keys
139
138
}
140
139
141
140
public init ? ( rawValue: Data ) {
142
141
// pop the first byte from the stream [EIP-2718]
143
142
let typeByte : UInt8 = rawValue. first ?? 0 // can't decode if we're the wrong type
144
- if typeByte != self . type. rawValue { return nil }
143
+ guard self . type. rawValue == typeByte else { return nil }
145
144
146
145
guard let totalItem = RLP . decode ( rawValue. dropFirst ( 1 ) ) else { return nil }
147
146
guard let rlpItem = totalItem [ 0 ] else { return nil }
148
- if rlpItem . count != RlpKey . total . rawValue { return nil }
147
+ guard RlpKey . allCases . count == rlpItem . count else { return nil }
149
148
150
149
// we've validated the item count, so rlpItem[keyName] is guaranteed to return something not nil
151
150
// swiftlint:disable force_unwrapping
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ extension EIP2930Envelope {
105
105
}
106
106
107
107
// RLP encoding positions
108
- fileprivate enum RlpKey : Int {
108
+ private enum RlpKey : Int , CaseIterable {
109
109
case chainId
110
110
case nonce
111
111
case gasPrice
@@ -117,17 +117,16 @@ extension EIP2930Envelope {
117
117
case sig_v
118
118
case sig_r
119
119
case sig_s
120
- case total // not a real entry, used to auto-size based on number of keys
121
120
}
122
121
123
122
public init ? ( rawValue: Data ) {
124
123
// pop the first byte from the stream [EIP-2718]
125
124
let typeByte : UInt8 = rawValue. first ?? 0 // can't decode if we're the wrong type
126
- if typeByte != self . type. rawValue { return nil }
125
+ guard self . type. rawValue == typeByte else { return nil }
127
126
128
127
guard let totalItem = RLP . decode ( rawValue. dropFirst ( 1 ) ) else { return nil }
129
128
guard let rlpItem = totalItem [ 0 ] else { return nil }
130
- if rlpItem . count != RlpKey . total . rawValue { return nil }
129
+ guard RlpKey . allCases . count == rlpItem . count else { return nil }
131
130
132
131
// we've validated the item count, so rlpItem[keyIndex] is guaranteed to return something not nil
133
132
// swiftlint:disable force_unwrapping
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ extension LegacyEnvelope {
107
107
self . s = try container. decodeHex ( to: BigUInt . self, key: . s)
108
108
}
109
109
110
- fileprivate enum RlpKey : Int {
110
+ private enum RlpKey : Int , CaseIterable {
111
111
case nonce
112
112
case gasPrice
113
113
case gasLimit
@@ -117,13 +117,12 @@ extension LegacyEnvelope {
117
117
case sig_v
118
118
case sig_r
119
119
case sig_s
120
- case total
121
120
}
122
121
123
122
public init ? ( rawValue: Data ) {
124
123
guard let totalItem = RLP . decode ( rawValue) else { return nil }
125
124
guard let rlpItem = totalItem [ 0 ] else { return nil }
126
- if rlpItem . count != RlpKey . total . rawValue { return nil }
125
+ guard RlpKey . allCases . count == rlpItem . count else { return nil }
127
126
128
127
// we've validated the item count, so rlpItem[key] is guaranteed to return something not nil
129
128
// swiftlint:disable force_unwrapping
You can’t perform that action at this time.
0 commit comments