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
|`ink(extension = N: u32)`| Yes | - | Determines the unique function ID of the chain extension method. |
76
+
|`ink(function = N: u16)`| Yes | - | Determines the unique function ID within the chain extension. |
60
77
|`ink(handle_status = flag: bool)`| Optional |`true`| Assumes that the returned status code of the chain extension method always indicates success and therefore always loads and decodes the output buffer of the call. |
61
78
62
79
As with all ink! attributes multiple of them can either appear in a contiguous list:
It is possible to use multiple exposed chain extensions in the single environment of a smart contract.
471
+
The declaration procedure of the chain extension stays the same.
472
+
473
+
Suppose we want to combine two chain extension called `Psp22Extension` and `FetchRandom`, ink! provides
474
+
a useful macro [`ink::combine_extensions!`](https://docs.rs/ink/5.0.0-rc/ink/macro.combine_extensions.html) that allows to construct the structure combining
475
+
the aforementioned chain extensions like so:
476
+
```rust
477
+
ink::combine_extensions! {
478
+
/// This extension combines the `FetchRandom` and `Psp22Extension` extensions.
479
+
/// It is possible to combine any number of extensions in this way.
480
+
///
481
+
/// This structure is an instance that is returned by the `self.env().extension()` call.
482
+
pubstructCombinedChainExtension {
483
+
/// The instance of the `Psp22Extension` chain extension.
484
+
///
485
+
/// It provides you access to `PSP22` functionality.
486
+
pubpsp22:Psp22Extension,
487
+
/// The instance of the `FetchRandom` chain extension.
488
+
///
489
+
/// It provides you access to randomness functionality.
490
+
pubrand:FetchRandom,
491
+
}
492
+
}
493
+
```
494
+
495
+
The combined structure is called `CombinedChainExtension`, and we can refer to it
496
+
when specifying the chain extension type in `Environment`:
497
+
```rust
498
+
typeChainExtension=CombinedChainExtension;
499
+
```
500
+
501
+
Each extension's method can be called by accessing it via the name of the field of `CombineChainExtension`:
The ink! repository contains the [full example](https://github.com/paritytech/ink/tree/master/integration-tests/combined-extension) illustrating how to combine existing chain extensions
512
+
and mock them for testing.
513
+
:::
514
+
515
+
516
+
## Mocking Chain Extension
517
+
518
+
You can mock chain extensions for unit testing purposes.
519
+
This can be achieved by implementing the [`ink::env::test::ChainExtension`](https://docs.rs/ink_env/latest/ink_env/test/trait.ChainExtension.html) trait.
0 commit comments