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' ABI 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' ABI 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
+
/// but **it does not add the data offset for dynamic types!!** To return single value **with data offset** use the following instead:
196
+
/// ```
197
+
/// ABIEncoder.encode(types: [type], values: [value] as [AnyObject])
198
+
/// ```
199
+
/// Almost identical to use of `web3.eth.abi.encodeParameter` in web3.js.
200
+
/// Calling `web3.eth.abi.encodeParameter('string','test')` in web3.js will return the following:
// MARK: - SoliditySHA3 implementation based on web3js
396
424
397
425
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
-
*/
426
+
427
+
/// A convenience implementation of web3js [soliditySha3](https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html?highlight=soliditySha3#soliditysha3)
428
+
/// that is based on web3swift [`ABIEncoder`](https://github.com/skywinder/web3swift/blob/develop/Sources/web3swift/EthereumABI/ABIEncoding.swift ).
429
+
/// - Parameter values: an array of values to hash. Supported types are: `Int/UInt` (any of 8, 16, 32, 64 bits long),
430
+
/// decimal or hexadecimal `String`, `Bool`, `Data`, `[UInt8]`, `EthereumAddress`, `[IntegerLiteralType]`, `BigInt` or `BigUInt`.
431
+
/// - 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)
437
+
/// that is based on web3swift [`ABIEncoder`](https://github.com/skywinder/web3swift/blob/develop/Sources/web3swift/EthereumABI/ABIEncoding.swift ).
438
+
/// - Parameter value: a value to hash. Supported types are: `Int/UInt` (any of 8, 16, 32, 64 bits long),
439
+
/// decimal or hexadecimal `String`, `Bool`, `Data`, `[UInt8]`, `EthereumAddress`, `[IntegerLiteralType]`, `BigInt` or `BigUInt`.
440
+
/// - Returns: solidity SHA3, `nil` if hashing failed or throws if type is not supported.
406
441
staticfunc soliditySha3(_ value:Any)throws->Data{
407
442
iflet values = value as?[Any]{
408
443
returntryabiEncode(values).sha3(.keccak256)
@@ -460,6 +495,6 @@ public extension ABIEncoder {
460
495
}elseiflet data =ABIEncoder.convertToData(value asAnyObject){
461
496
return data
462
497
}
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)).")
498
+
throwWeb3Error.inputError(desc:"SoliditySha3: `abiEncode` accepts an Int/UInt (any of 8, 16, 32, 64 bits long), decimal or HEX string, Bool, Data, [UInt8], EthereumAddress, [IntegerLiteralType], BigInt or BigUInt instance. Given value is of type \(type(of: value)).")
0 commit comments