@@ -168,45 +168,79 @@ extension ABI.Element.ParameterType: Equatable {
168
168
}
169
169
170
170
extension ABI . Element . Function {
171
+ /// String representation of a function, e.g. `transfer(address,uint256)`.
171
172
public var signature : String {
172
173
return " \( name ?? " " ) ( \( inputs. map { $0. type. abiRepresentation } . joined ( separator: " , " ) ) ) "
173
174
}
174
175
176
+ /// Function selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
177
+ @available ( * , deprecated, renamed: " selector " , message: " Please, use 'selector' property instead. " )
175
178
public var methodString : String {
179
+ return selector
180
+ }
181
+
182
+ /// Function selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
183
+ public var selector : String {
176
184
return String ( signature. sha3 ( . keccak256) . prefix ( 8 ) )
177
185
}
178
186
187
+ /// Function selector (e.g. `0xcafe1234`) but as raw bytes.
188
+ @available ( * , deprecated, renamed: " selectorEncoded " , message: " Please, use 'selectorEncoded' property instead. " )
179
189
public var methodEncoding : Data {
180
- return signature. data ( using: . ascii) !. sha3 ( . keccak256) [ 0 ... 3 ]
190
+ return selectorEncoded
191
+ }
192
+
193
+ /// Function selector (e.g. `0xcafe1234`) but as raw bytes.
194
+ public var selectorEncoded : Data {
195
+ return Data . fromHex ( selector) !
181
196
}
182
197
}
183
198
184
199
// MARK: - Event topic
185
200
extension ABI . Element . Event {
201
+ /// String representation of an event, e.g. `ContractCreated(address)`.
186
202
public var signature : String {
187
203
return " \( name) ( \( inputs. map { $0. type. abiRepresentation } . joined ( separator: " , " ) ) ) "
188
204
}
189
205
206
+ /// Hashed signature of an event, e.g. `0xcf78cf0d6f3d8371e1075c69c492ab4ec5d8cf23a1a239b6a51a1d00be7ca312`.
190
207
public var topic : Data {
191
208
return signature. data ( using: . ascii) !. sha3 ( . keccak256)
192
209
}
193
210
}
194
211
195
212
extension ABI . Element . EthError {
213
+ /// String representation of an error, e.g. `TrasferFailed(address)`.
196
214
public var signature : String {
197
215
return " \( name) ( \( inputs. map { $0. type. abiRepresentation } . joined ( separator: " , " ) ) ) "
198
216
}
199
217
218
+ /// Error selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
219
+ @available ( * , deprecated, renamed: " selector " , message: " Please, use 'selector' property instead. " )
200
220
public var methodString : String {
221
+ return selector
222
+ }
223
+
224
+ /// Error selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
225
+ public var selector : String {
201
226
return String ( signature. sha3 ( . keccak256) . prefix ( 8 ) )
202
227
}
203
228
229
+ /// Error selector (e.g. `0xcafe1234`) but as raw bytes.
230
+ @available ( * , deprecated, renamed: " selectorEncoded " , message: " Please, use 'selectorEncoded' property instead. " )
204
231
public var methodEncoding : Data {
205
- return signature. data ( using: . ascii) !. sha3 ( . keccak256) [ 0 ... 3 ]
232
+ return selectorEncoded
233
+ }
234
+
235
+ /// Error selector (e.g. `0xcafe1234`) but as raw bytes.
236
+ public var selectorEncoded : Data {
237
+ return Data . fromHex ( selector) !
206
238
}
207
239
}
208
240
209
241
extension ABI . Element . ParameterType : ABIEncoding {
242
+
243
+ /// Returns a valid solidity type like `address`, `uint128` or any other built-in type from Solidity.
210
244
public var abiRepresentation : String {
211
245
switch self {
212
246
case . uint( let bits) :
0 commit comments