Skip to content

Commit 76af73f

Browse files
committed
docs: Update contract_ref! and message_builder! docs and examples
1 parent f272211 commit 76af73f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

crates/ink/src/contract_ref.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ use ink_primitives::Address;
117117
///
118118
/// # Usage outside the `#[ink::contract]` context
119119
///
120-
/// The macro expects two arguments:
120+
/// The macro expects up to three arguments:
121121
/// - The first argument is the path to the trait, e.g. `Erc20` or `erc20::Erc20`.
122122
/// - The second argument is the type of the [`ink_env::Environment`].
123+
/// - The third argument is the marker type for the ABI (i.e. [`ink::abi::Ink`] or
124+
/// [`ink::abi::Sol`]).
123125
///
124126
/// If the second argument is not specified, the macro uses the `Environment` type alias.
127+
/// If the third argument is not specified, the macro uses the "default" ABI,
128+
/// which depending on the ABI specified in the project's manifest
129+
/// (see https://use.ink/docs/v6/basics/abi/ for details).
125130
///
126131
/// ```rust
127132
/// use ink::contract_ref;
@@ -156,6 +161,7 @@ use ink_primitives::Address;
156161
/// type AliasWithDefaultEnv = contract_ref!(Erc20, DefaultEnvironment);
157162
/// type AliasWithCustomEnv = contract_ref!(Erc20, CustomEnv);
158163
/// type AliasWithGenericEnv<E> = contract_ref!(Erc20, E);
164+
/// type AliasWithCustomAbi = contract_ref!(Erc20, DefaultEnvironment, ink::abi::Ink);
159165
///
160166
/// fn default(mut contract: contract_ref!(Erc20, DefaultEnvironment)) {
161167
/// let total_supply = contract.total_supply();
@@ -194,6 +200,15 @@ use ink_primitives::Address;
194200
/// generic(contract)
195201
/// }
196202
///
203+
/// fn custom_abi(mut contract: contract_ref!(Erc20, DefaultEnvironment, ink::abi::Ink)) {
204+
/// let total_supply = contract.total_supply();
205+
/// contract.transfer(total_supply, contract.as_ref().clone());
206+
/// }
207+
///
208+
/// fn custom_alias_abi(mut contract: AliasWithCustomAbi) {
209+
/// custom_abi(contract)
210+
/// }
211+
///
197212
/// type Environment = DefaultEnvironment;
198213
///
199214
/// fn contract_ref_default_behaviour(mut contract: contract_ref!(Erc20)) {

crates/ink/src/message_builder.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727
///
2828
/// # Usage
2929
///
30-
/// The macro expects two arguments:
30+
/// The macro expects up to three arguments:
3131
/// - The first argument is the path to the trait, e.g. `Erc20` or `erc20::Erc20`.
3232
/// - The second argument is the type of the [`ink_env::Environment`].
33+
/// - The third argument is the marker type for the ABI (i.e. [`ink::abi::Ink`] or
34+
/// [`ink::abi::Sol`]).
3335
///
3436
/// If the second argument is not specified, the macro uses the
3537
/// [`ink_env::DefaultEnvironment`].
38+
/// If the third argument is not specified, the macro uses the "default" ABI,
39+
/// which depending on the ABI specified in the project's manifest
40+
/// (see https://use.ink/docs/v6/basics/abi/ for details).
3641
///
3742
/// ```rust
3843
/// use ink::message_builder;
@@ -123,6 +128,13 @@
123128
/// contract.transfer(total_supply, to).exec(&executor).unwrap();
124129
/// }
125130
///
131+
/// fn custom_abi(to: Address) {
132+
/// let executor = ExampleExecutor::<DefaultEnvironment>::new();
133+
/// let mut contract = message_builder!(Erc20, DefaultEnvironment, ink::abi::Ink);
134+
/// let total_supply = contract.total_supply().exec(&executor).unwrap().unwrap();
135+
/// contract.transfer(total_supply, to).exec(&executor).unwrap();
136+
/// }
137+
///
126138
/// fn generic<E>(to: Address)
127139
/// where
128140
/// E: ink_env::Environment,

0 commit comments

Comments
 (0)