You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Performs ABI encoding conforming to [the documentation of encoding](https://docs.soliditylang.org/en/develop/abi-spec.html#basic-design) in Solidity.
132
+
/// Overloading to support `ABI.Element.InOut` as the type of the `types` array.
133
+
/// Identical to use of `web3.eth.abi.encodeParameters` in web3.js.
134
134
/// - Parameters:
135
-
/// - types: Contract element InOut to encode
136
-
/// - values: Contract values of a given element to encode
137
-
/// - Returns: Encoded data
135
+
/// - types: an array of values' Solidity types. Must be declared in the same order as entries in `values` or encoding will fail;
136
+
/// - values: an array of values to encode. Must be declared in the same order as entries in `types` or encoding will fail;
137
+
/// - Returns: ABI encoded data, e.g. function call parameters. Returns `nil` if:
138
+
/// - `types.count != values.count`;
139
+
/// - encoding of at least one value has failed (e.g. type mismatch).
letparams= types.compactMap{ el ->ABI.Element.ParameterTypein
@@ -143,11 +145,14 @@ extension ABIEncoder {
143
145
returnencode(types: params, values: values)
144
146
}
145
147
146
-
/// Encode Elements Prarmeter Type
148
+
/// Performs ABI encoding conforming to [the documentation of encoding](https://docs.soliditylang.org/en/develop/abi-spec.html#basic-design) in Solidity.
149
+
/// Identical to use of `web3.eth.abi.encodeParameters` in web3.js.
147
150
/// - Parameters:
148
-
/// - types: Contract parameters type to encode
149
-
/// - values: Contract values of a given element to encode
150
-
/// - Returns: Encoded data
151
+
/// - types: an array of values' Solidity types. Must be declared in the same order as entries in `values` or encoding will fail;
152
+
/// - values: an array of values to encode. Must be declared in the same order as entries in `types` or encoding will fail;
153
+
/// - Returns: ABI encoded data, e.g. function call parameters. Returns `nil` if:
154
+
/// - `types.count != values.count`;
155
+
/// - encoding of at least one value has failed (e.g. type mismatch).
/// Performs ABI encoding conforming to [the documentation of encoding](https://docs.soliditylang.org/en/develop/abi-spec.html#basic-design) in Solidity.
195
+
///
196
+
/// **It does not add the data offset for dynamic types!!** To return single value **with data offset** use the following instead:
197
+
/// ```swift
198
+
/// ABIEncoder.encode(types: [type], values: [value] as [AnyObject])
199
+
/// ```
200
+
/// Almost identical to use of `web3.eth.abi.encodeParameter` in web3.js.
201
+
/// Calling `web3.eth.abi.encodeParameter('string','test')` in web3.js will return the following:
// MARK: - SoliditySHA3 implementation based on web3js
396
425
397
426
publicextensionABIEncoder{
398
-
/**
399
-
A convenience implementation of web3js [soliditySha3](https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html?highlight=soliditySha3#soliditysha3)
400
-
that is based on web3swift [`ABIEncoder`](https://github.com/skywinder/web3swift/blob/develop/Sources/web3swift/EthereumABI/ABIEncoding.swift ).
401
-
*/
427
+
428
+
/// A convenience implementation of web3js [soliditySha3](https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html?highlight=soliditySha3#soliditysha3)
429
+
/// that is based on web3swift [`ABIEncoder`](https://github.com/skywinder/web3swift/blob/develop/Sources/web3swift/EthereumABI/ABIEncoding.swift ).
430
+
/// - Parameter values: an array of values to hash. Supported types are: `Int/UInt` (any of 8, 16, 32, 64 bits long),
431
+
/// decimal or hexadecimal `String`, `Bool`, `Data`, `[UInt8]`, `EthereumAddress`, `[IntegerLiteralType]`, `BigInt` or `BigUInt`.
432
+
/// - Returns: solidity SHA3, `nil` if hashing failed or throws if type is not supported.
/// A convenience implementation of web3js [soliditySha3](https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html?highlight=soliditySha3#soliditysha3)
438
+
/// that is based on web3swift [`ABIEncoder`](https://github.com/skywinder/web3swift/blob/develop/Sources/web3swift/EthereumABI/ABIEncoding.swift ).
439
+
/// - Parameter value: a value to hash. Supported types are: `Int/UInt` (any of 8, 16, 32, 64 bits long),
440
+
/// decimal or hexadecimal `String`, `Bool`, `Data`, `[UInt8]`, `EthereumAddress`, `[IntegerLiteralType]`, `BigInt` or `BigUInt`.
441
+
/// - Returns: solidity SHA3, `nil` if hashing failed or throws if type is not supported.
406
442
staticfunc soliditySha3(_ value:Any)throws->Data{
407
443
iflet values = value as?[Any]{
408
444
returntryabiEncode(values).sha3(.keccak256)
@@ -460,6 +496,6 @@ public extension ABIEncoder {
460
496
}elseiflet data =ABIEncoder.convertToData(value asAnyObject){
461
497
return data
462
498
}
463
-
throwWeb3Error.inputError(desc:"SoliditySha3: `abiEncode` accepts an Int/UInt (any of 8, 16, 32, 64 bits long), HEX string, Bool, Data, BigInt or BigUInt instance. Given value is of type \(type(of: value)).")
499
+
throwWeb3Error.inputError(desc:"SoliditySha3: `abiEncode` accepts an Int/UInt (any of 8, 16, 32, 64 bits long), decimal or hexadecimal string, Bool, Data, [UInt8], EthereumAddress, [IntegerLiteralType], BigInt or BigUInt instance. Given value is of type \(type(of: value)).")
0 commit comments