@@ -117,6 +117,113 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream {
117
117
///
118
118
/// The `#[ink::contract]` macro can be provided with some additional comma-separated
119
119
/// header arguments:
120
+ /// - `abi: String`
121
+ ///
122
+ /// Tells the ink! code generator which ABI (Application Binary Interface)
123
+ /// specification(s) to support for contract interactions
124
+ /// (i.e. which calling conventions to use for message calls).
125
+ ///
126
+ /// **Default value:** `"ink"`
127
+ ///
128
+ /// **Allowed values:** `"ink"`, `"sol"`, `"all"`
129
+ ///
130
+ /// **Usage Example:**
131
+ /// ```
132
+ /// #[ink::contract(abi = "sol")]
133
+ /// mod my_contract {
134
+ /// # #[ink(storage)]
135
+ /// # pub struct MyStorage;
136
+ /// # impl MyStorage {
137
+ /// # #[ink(constructor)]
138
+ /// // #[bar]
139
+ /// # pub fn construct() -> Self { MyStorage {} }
140
+ /// # #[ink(message)]
141
+ /// // #[foo]
142
+ /// # pub fn message(&self) {}
143
+ /// # }
144
+ /// // ...
145
+ /// }
146
+ /// ```
147
+ ///
148
+ /// - `abi = "ink"`
149
+ ///
150
+ /// The code generator follows the ink! ABI specification. This means:
151
+ /// - By default, message selectors are generated according to the [ink! ABI
152
+ /// specification for selectors][ink-spec-selector]
153
+ /// - Message selectors can be manually overridden using the [`selector` attribute
154
+ /// argument][ink-selector-attribute]
155
+ /// - Parity's [SCALE Codec][scale-codec] is used for input/output encoding/decoding
156
+ ///
157
+ /// - `abi = "sol"`
158
+ ///
159
+ /// The code generator follows the [Solidity ABI specification][sol-spec].
160
+ /// This means:
161
+ /// - Message selectors are **always** generated according to the [Solidity ABI
162
+ /// specification for function selectors][sol-spec-selector]
163
+ /// - Message selector manual overrides using the [`selector` attribute
164
+ /// argument][ink-selector-attribute] are ignored
165
+ /// - [Solidity ABI encoding][sol-abi-codec] is used for input/output
166
+ /// encoding/decoding
167
+ ///
168
+ /// - `abi = "all"`
169
+ ///
170
+ /// The code generator will generate selectors and input/output encoding/decoding
171
+ /// logic for both ink! and Solidity ABI.
172
+ ///
173
+ /// Please note that your contract sizes will get larger if you support both the ink!
174
+ /// and Solidity ABI.
175
+ ///
176
+ /// For contracts that support Solidity ABI encoding
177
+ /// (i.e. `abi = "sol"` or `abi = "all"`), all types used as constructor/message
178
+ /// arguments and return types must define a mapping to an equivalent Solidity type.
179
+ /// This mapping is defined using the [`SolEncode`][sol-trait-encode] and
180
+ /// [`SolDecode`][sol-trait-decode] traits that are analogs to `scale::Encode` and
181
+ /// `scale::Decode` (but for Solidity ABI encoding/decoding).
182
+ ///
183
+ /// [`SolEncode`][sol-trait-encode] and [`SolDecode`][sol-trait-decode] are implemented
184
+ /// for the following Rust/ink! primitive types creating a mapping
185
+ /// to the corresponding Solidity ABI types as shown in the table below:
186
+ ///
187
+ /// | Rust/ink! type | Solidity ABI type | Notes |
188
+ /// | -------------- | ----------------- | ----- |
189
+ /// | `bool` | `bool` ||
190
+ /// | `iN` for `N ∈ {8,16,32,64,128}` | `intN` | e.g `i8` <=> `int8` |
191
+ /// | `uN` for `N ∈ {8,16,32,64,128}` | `uintN` | e.g `u8` <=> `uint8` |
192
+ /// | `U256` | `uint256` ||
193
+ /// | `String` | `string` ||
194
+ /// | `Address` | `address` ||
195
+ /// | `[T; N]` for `const N: usize` | `T[N]` | e.g. `[i8; 64]` <=> `int8[64]` |
196
+ /// | `Vec<T>` | `T[]` | e.g. `Vec<i8>` <=> `int8[]` |
197
+ /// | `AsSolBytes<[u8; N]>` for `1 <= N <= 32` | `bytesN` | e.g. `AsSolBytes<[u8; 1]>` <=> `bytes1` |
198
+ /// | `AsSolBytes<Vec<u8>>` | `bytes` ||
199
+ /// | `(T1, T2, T3, ... T12)` | `(U1, U2, U3, ... U12)` | where `T1` <=> `U1`, ... `T12` <=> `U12` e.g. `(bool, u8, Address)` <=> `(bool, uint8, address)` |
200
+ ///
201
+ /// [`SolEncode`][sol-trait-encode] is additionally implemented for reference and smart
202
+ /// pointer types below:
203
+ ///
204
+ /// | Rust/ink! type | Solidity ABI type | Notes |
205
+ /// | -------------- | ----------------- | ----- |
206
+ /// | `&str`, `&mut str`, `Box<str>` | string ||
207
+ /// | `&T`, `&mut T`, `Box<T>` | T | e.g. `&i8 <=> int8` |
208
+ /// | `&[T]`, `&mut [T]`, `Box<[T]>` | T[] | e.g. `&[i8]` <=> `int8[]` |
209
+ ///
210
+ /// See the rustdoc for [`SolEncode`][sol-trait-encode] and
211
+ /// [`SolDecode`][sol-trait-decode] for instructions for implementing the traits for
212
+ /// custom arbitrary types.
213
+ ///
214
+ /// Please note that Rust's [coherence/orphan rules][rust-coherence] mean that you can
215
+ /// only implement the [`SolEncode`][sol-trait-encode] and
216
+ /// [`SolDecode`][sol-trait-decode] traits for local types.
217
+ ///
218
+ /// [ink-spec-selector]: https://use.ink/basics/selectors/
219
+ /// [ink-selector-attribute]: https://use.ink/macros-attributes/selector
220
+ /// [scale-codec]: https://docs.rs/parity-scale-codec/latest/parity_scale_codec
221
+ /// [sol-spec]: https://docs.soliditylang.org/en/latest/abi-spec.html
222
+ /// [sol-spec-selector]: https://docs.soliditylang.org/en/latest/abi-spec.html#function-selector
223
+ /// [sol-abi-codec]: https://docs.soliditylang.org/en/latest/abi-spec.html#formal-specification-of-the-encoding
224
+ /// [sol-trait-encode]: https://docs.rs/ink/latest/ink/trait.SolEncode.html
225
+ /// [sol-trait-decode]: https://docs.rs/ink/latest/ink/trait.SolEncode.html
226
+ /// [rust-coherence]: https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
120
227
///
121
228
/// - `keep_attr: String`
122
229
///
0 commit comments