@@ -168,45 +168,79 @@ extension ABI.Element.ParameterType: Equatable {
168168}
169169
170170extension ABI . Element . Function {
171+ /// String representation of a function, e.g. `transfer(address,uint256)`.
171172 public var signature : String {
172173 return " \( name ?? " " ) ( \( inputs. map { $0. type. abiRepresentation } . joined ( separator: " , " ) ) ) "
173174 }
174175
176+ /// Function selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
177+ @available ( * , deprecated, renamed: " selector " , message: " Please, use 'selector' property instead. " )
175178 public var methodString : String {
179+ return selector
180+ }
181+
182+ /// Function selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
183+ public var selector : String {
176184 return String ( signature. sha3 ( . keccak256) . prefix ( 8 ) )
177185 }
178186
187+ /// Function selector (e.g. `0xcafe1234`) but as raw bytes.
188+ @available ( * , deprecated, renamed: " selectorEncoded " , message: " Please, use 'selectorEncoded' property instead. " )
179189 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) !
181196 }
182197}
183198
184199// MARK: - Event topic
185200extension ABI . Element . Event {
201+ /// String representation of an event, e.g. `ContractCreated(address)`.
186202 public var signature : String {
187203 return " \( name) ( \( inputs. map { $0. type. abiRepresentation } . joined ( separator: " , " ) ) ) "
188204 }
189205
206+ /// Hashed signature of an event, e.g. `0xcf78cf0d6f3d8371e1075c69c492ab4ec5d8cf23a1a239b6a51a1d00be7ca312`.
190207 public var topic : Data {
191208 return signature. data ( using: . ascii) !. sha3 ( . keccak256)
192209 }
193210}
194211
195212extension ABI . Element . EthError {
213+ /// String representation of an error, e.g. `TrasferFailed(address)`.
196214 public var signature : String {
197215 return " \( name) ( \( inputs. map { $0. type. abiRepresentation } . joined ( separator: " , " ) ) ) "
198216 }
199217
218+ /// Error selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
219+ @available ( * , deprecated, renamed: " selector " , message: " Please, use 'selector' property instead. " )
200220 public var methodString : String {
221+ return selector
222+ }
223+
224+ /// Error selector, e.g. `"cafe1234"`. Without hex prefix `0x`.
225+ public var selector : String {
201226 return String ( signature. sha3 ( . keccak256) . prefix ( 8 ) )
202227 }
203228
229+ /// Error selector (e.g. `0xcafe1234`) but as raw bytes.
230+ @available ( * , deprecated, renamed: " selectorEncoded " , message: " Please, use 'selectorEncoded' property instead. " )
204231 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) !
206238 }
207239}
208240
209241extension ABI . Element . ParameterType : ABIEncoding {
242+
243+ /// Returns a valid solidity type like `address`, `uint128` or any other built-in type from Solidity.
210244 public var abiRepresentation : String {
211245 switch self {
212246 case . uint( let bits) :
0 commit comments