ink-analyzer 0.11.2

A library for semantic analysis of ink! smart contracts.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
//! Hover content for ink! attribute macros.

/// Ref: https://github.com/use-ink/ink/pull/2621
pub const CHAIN_EXTENSION_DOC_DEPRECATED: &str = r#"
ink! chain extensions are deprecated. See https://github.com/use-ink/ink/pull/2621 for details.
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v5.0.0-rc.1/crates/ink/macro/src/lib.rs#L897-L1337>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.chain_extension.html>.
pub const CHAIN_EXTENSION_DOC: &str = r#"
# Attribute

`#[ink::chain_extension]`

# Description

Defines the interface for a chain extension.

# Structure

The interface consists of an error code that indicates lightweight errors
as well as the definition of some chain extension methods.

The overall structure follows that of a simple Rust trait definition.
The error code is defined as an associated type definition of the trait definition.
The methods are defined as associated trait methods without implementation.

Chain extension methods must not have a `self` receiver such as `&self` or `&mut self`
and must have inputs and output that implement the SCALE encoding and decoding.
Their return value follows specific rules that can be altered using the
`handle_status` attribute which is described in more detail below.

# Usage

Usually the chain extension definition using this procedural macro is provided
by the author of the chain extension in a separate crate.
ink! smart contracts using this chain extension simply depend on this crate
and use its associated environment definition in order to make use of
the methods provided by the chain extension.

# Macro Attributes

The macro supports only one required argument:

- `extension = N: u16`:

    The runtime may have several chain extensions at the same time. The `extension`
    identifier points to the corresponding chain extension in the runtime.
    The value should be the same as during the definition of the chain extension.

# Method Attributes

There are three different attributes with which the chain extension methods
can be flagged:

| Attribute | Required | Default Value | Description |
|:----------|:--------:|:--------------|:-----------:|
| `ink(function = N: u16)` | Yes | - | Determines the unique function ID within the
chain extension. | | `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. |

As with all ink! attributes multiple of them can either appear in a contiguous list:
```
# type Access = i32;
# #[ink::chain_extension(extension = 1)]
# pub trait MyChainExtension {
#     type ErrorCode = i32;
#[ink(function = 5, handle_status = false)]
fn key_access_for_account(key: &[u8], account: &[u8]) -> Access;
# }
```
…or as multiple stand alone ink! attributes applied to the same item:
```
# type Access = i32;
# #[ink::chain_extension(extension = 1)]
# pub trait MyChainExtension {
#     type ErrorCode = i32;
#[ink(function = 5)]
#[ink(handle_status = false)]
fn key_access_for_account(key: &[u8], account: &[u8]) -> Access;
# }
```

## Details: `handle_status`

Default value: `true`

By default all chain extension methods should return a `Result<T, E>` where `E:
From<Self::ErrorCode>`. The `Self::ErrorCode` represents the error code of the chain
extension. This means that a smart contract calling such a chain extension method
first queries the returned status code of the chain extension method and only loads
and decodes the output if the returned status code indicates a successful call.
This design was chosen as it is more efficient when no output besides the error
code is required for a chain extension call. When designing a chain extension try to
utilize the error code to return errors and only use the output buffer for information
that does not fit in a single `u32` value.

A chain extension method that is flagged with `handle_status = false` assumes that the
returned error code will always indicate success. Therefore it will always load and
decode the output buffer and loses the `E: From<Self::ErrorCode>` constraint for the
call.

Note that if a chain extension method does not return `Result<T, E>` where `E:
From<Self::ErrorCode>` but `handle_status = true` it will still return a value of type
`Result<T, Self::ErrorCode>`.

## Usage: `handle_status`

Use both `handle_status = false` and non-`Result<T, E>` return type for the same chain
extension method if a call to it may never fail and never returns a `Result` type.

# Combinations

Due to the possibility to flag a chain extension method with `handle_status` and
return or not `Result<T, E>` there are 4 different cases with slightly varying
semantics:

| `handle_status` | Returns `Result<T, E>` | Effects |
|:---------------:|:----------------:|:--------|
| `true`  | `true`  | The chain extension method is required to return a value of type
`Result<T, E>` where `E: From<Self::ErrorCode>`. A call will always check if the
returned status code indicates success and only then will load and decode the value in
the output buffer. | | `true`  | `false` | The chain extension method may return any
non-`Result` type. A call will always check if the returned status code indicates
success and only then will load and decode the value in the output buffer. The actual
return type of the chain extension method is still `Result<T, Self::ErrorCode>` when
the chain extension method was defined to return a value of type `T`. | | `false` |
`true`  | The chain extension method is required to return a value of type `Result<T,
E>`. A call will always assume that the returned status code indicates success and
therefore always load and decode the output buffer directly. | | `false` | `false` |
The chain extension method may return any non-`Result` type. A call will always assume
that the returned status code indicates success and therefore always load and decode
the output buffer directly. |

# Error Code

Every chain extension defines exactly one `ErrorCode` using the following syntax:

```
#[ink::chain_extension(extension = 0)]
pub trait MyChainExtension {
    type ErrorCode = MyErrorCode;

    // more definitions
}
```

The defined `ErrorCode` must implement `FromStatusCode` which should be implemented as
a more or less trivial conversion from the `u32` status code to a `Result<(),
Self::ErrorCode>`. The `Ok(())` value indicates that the call to the chain extension
method was successful.

By convention an error code of `0` represents success.
However, chain extension authors may use whatever suits their needs.

# Example: Definition

In the below example a chain extension is defined that allows its users to read and
write from and to the runtime storage using access privileges:

```
/// Custom chain extension to read to and write from the runtime.
#[ink::chain_extension(extension = 0)]
pub trait RuntimeReadWrite {
    type ErrorCode = ReadWriteErrorCode;

    /// Reads from runtime storage.
    ///
    /// # Note
    ///
    /// Actually returns a value of type `Result<Vec<u8>, Self::ErrorCode>`.
    #[ink(function = 1)]
    fn read(key: &[u8]) -> Vec<u8>;

    /// Reads from runtime storage.
    ///
    /// Returns the number of bytes read and up to 32 bytes of the
    /// read value. Unused bytes in the output are set to 0.
    ///
    /// # Errors
    ///
    /// If the runtime storage cell stores a value that requires more than
    /// 32 bytes.
    ///
    /// # Note
    ///
    /// This requires `ReadWriteError` to implement `From<ReadWriteErrorCode>`
    /// and may potentially return any `Self::ErrorCode` through its return value.
    #[ink(function = 2)]
    fn read_small(key: &[u8]) -> Result<(u32, [u8; 32]), ReadWriteError>;

    /// Writes into runtime storage.
    ///
    /// # Note
    ///
    /// Actually returns a value of type `Result<(), Self::ErrorCode>`.
    #[ink(function = 3)]
    fn write(key: &[u8], value: &[u8]);

    /// Returns the access allowed for the key for the caller.
    ///
    /// # Note
    ///
    /// Assumes to never fail the call and therefore always returns `Option<Access>`.
    #[ink(function = 4, handle_status = false)]
    fn access(key: &[u8]) -> Option<Access>;

    /// Unlocks previously acquired permission to access key.
    ///
    /// # Errors
    ///
    /// If the permission was not granted.
    ///
    /// # Note
    ///
    /// Assumes the call to never fail and therefore does _NOT_ require `UnlockAccessError`
    /// to implement `From<Self::ErrorCode>` as in the `read_small` method above.
    #[ink(function = 5, handle_status = false)]
    fn unlock_access(key: &[u8], access: Access) -> Result<(), UnlockAccessError>;
}
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteErrorCode {
#     InvalidKey,
#     CannotWriteToKey,
#     CannotReadFromKey,
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteError {
#     ErrorCode(ReadWriteErrorCode),
#     BufferTooSmall { required_bytes: u32 },
# }
# impl From<ReadWriteErrorCode> for ReadWriteError {
#     fn from(error_code: ReadWriteErrorCode) -> Self {
#         Self::ErrorCode(error_code)
#     }
# }
# impl From<scale::Error> for ReadWriteError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub struct UnlockAccessError {
#     reason: String,
# }
# impl From<scale::Error> for UnlockAccessError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo, Clone)]
# pub enum Access {
#     ReadWrite,
#     ReadOnly,
#     WriteOnly,
# }
# impl ink_env::chain_extension::FromStatusCode for ReadWriteErrorCode {
#     fn from_status_code(status_code: u32) -> Result<(), Self> {
#         match status_code {
#             0 => Ok(()),
#             1 => Err(Self::InvalidKey),
#             2 => Err(Self::CannotWriteToKey),
#             3 => Err(Self::CannotReadFromKey),
#             _ => panic!("encountered unknown status code"),
#         }
#     }
# }
```

All the error types and other utility types used in the chain extension definition
above are often required to implement various traits such as SCALE's `Encode` and
`Decode` as well as `scale-info`'s `TypeInfo` trait.

A full example of the above chain extension definition can be seen
[here](https://github.com/paritytech/ink/blob/017f71d60799b764425334f86b732cc7b7065fe6/crates/lang/macro/tests/ui/chain_extension/simple.rs).

# Example: Environment

In order to allow ink! smart contracts to use the above defined chain extension it
needs to be integrated into an `Environment` definition as shown below:

```
# type RuntimeReadWrite = i32;
#
use ink_env::{
    DefaultEnvironment,
    Environment,
};

#[derive(Clone)]
pub enum CustomEnvironment {}

impl Environment for CustomEnvironment {
    const MAX_EVENT_TOPICS: usize =
        <DefaultEnvironment as Environment>::MAX_EVENT_TOPICS;

    type AccountId = <DefaultEnvironment as Environment>::AccountId;
    type Balance = <DefaultEnvironment as Environment>::Balance;
    type Hash = <DefaultEnvironment as Environment>::Hash;
    type BlockNumber = <DefaultEnvironment as Environment>::BlockNumber;
    type Timestamp = <DefaultEnvironment as Environment>::Timestamp;

    type ChainExtension = RuntimeReadWrite;
}
```

Above we defined the `CustomEnvironment` which defaults to ink!'s `DefaultEnvironment`
for all constants and types but the `ChainExtension` type which is assigned to our
newly defined chain extension.

# Example: Usage

An ink! smart contract can use the above defined chain extension through the
`Environment` definition defined in the last example section using the `env` macro
parameter as shown below.

Note that chain extension methods are accessible through `Self::extension()` or
`self.extension()`. For example as in `Self::extension().read(...)` or
`self.extension().read(...)`.

```
#[ink::contract(env = CustomEnvironment)]
mod read_writer {
    #[ink(storage)]
    pub struct ReadWriter {}

    impl ReadWriter {
        #[ink(constructor)]
        pub fn new() -> Self { Self {} }

        #[ink(message)]
        pub fn read(&self, key: Vec<u8>) -> Result<Vec<u8>, ReadWriteErrorCode> {
            self.env()
                .extension()
                .read(&key)
        }

        #[ink(message)]
        pub fn read_small(&self, key: Vec<u8>) -> Result<(u32, [u8; 32]), ReadWriteError> {
            self.env()
                .extension()
                .read_small(&key)
        }

        #[ink(message)]
        pub fn write(
            &self,
            key: Vec<u8>,
            value: Vec<u8>,
        ) -> Result<(), ReadWriteErrorCode> {
            self.env()
                .extension()
                .write(&key, &value)
        }

        #[ink(message)]
        pub fn access(&self, key: Vec<u8>) -> Option<Access> {
            self.env()
                .extension()
                .access(&key)
        }

        #[ink(message)]
        pub fn unlock_access(&self, key: Vec<u8>, access: Access) -> Result<(), UnlockAccessError> {
            self.env()
                .extension()
                .unlock_access(&key, access)
        }
    }
# /// Custom chain extension to read to and write from the runtime.
# #[ink::chain_extension(extension = 13)]
# pub trait RuntimeReadWrite {
#     type ErrorCode = ReadWriteErrorCode;
#     #[ink(function = 1)]
#     fn read(key: &[u8]) -> Vec<u8>;
#     #[ink(function = 2)]
#     fn read_small(key: &[u8]) -> Result<(u32, [u8; 32]), ReadWriteError>;
#     #[ink(function = 3)]
#     fn write(key: &[u8], value: &[u8]);
#     #[ink(function = 4, handle_status = false)]
#     fn access(key: &[u8]) -> Option<Access>;
#     #[ink(function = 5, handle_status = false)]
#     fn unlock_access(key: &[u8], access: Access) -> Result<(), UnlockAccessError>;
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteErrorCode {
#     InvalidKey,
#     CannotWriteToKey,
#     CannotReadFromKey,
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteError {
#     ErrorCode(ReadWriteErrorCode),
#     BufferTooSmall { required_bytes: u32 },
# }
# impl From<ReadWriteErrorCode> for ReadWriteError {
#     fn from(error_code: ReadWriteErrorCode) -> Self {
#         Self::ErrorCode(error_code)
#     }
# }
# impl From<scale::Error> for ReadWriteError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub struct UnlockAccessError {
#     reason: String,
# }
# impl From<scale::Error> for UnlockAccessError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo, Clone)]
# pub enum Access {
#     ReadWrite,
#     ReadOnly,
#     WriteOnly,
# }
# impl ink_env::chain_extension::FromStatusCode for ReadWriteErrorCode {
#     fn from_status_code(status_code: u32) -> Result<(), Self> {
#         match status_code {
#             0 => Ok(()),
#             1 => Err(Self::InvalidKey),
#             2 => Err(Self::CannotWriteToKey),
#             3 => Err(Self::CannotReadFromKey),
#             _ => panic!("encountered unknown status code"),
#         }
#     }
# }
# #[derive(Clone)]
# pub enum CustomEnvironment {}
# impl ink_env::Environment for CustomEnvironment {
#     const MAX_EVENT_TOPICS: usize =
#         <ink_env::DefaultEnvironment as ink_env::Environment>::MAX_EVENT_TOPICS;
#
#     type AccountId = <ink_env::DefaultEnvironment as ink_env::Environment>::AccountId;
#     type Balance = <ink_env::DefaultEnvironment as ink_env::Environment>::Balance;
#     type Hash = <ink_env::DefaultEnvironment as ink_env::Environment>::Hash;
#     type BlockNumber = <ink_env::DefaultEnvironment as ink_env::Environment>::BlockNumber;
#     type Timestamp = <ink_env::DefaultEnvironment as ink_env::Environment>::Timestamp;
#
#     type ChainExtension = RuntimeReadWrite;
# }
}
```

# Technical Limitations

- Due to technical limitations it is not possible to refer to the `ErrorCode`
  associated type using `Self::ErrorCode` anywhere within the chain extension and its
  defined methods. Instead chain extension authors should directly use the error code
  type when required. This limitation might be lifted in future versions of ink!.
- It is not possible to declare other chain extension traits as super traits or super
  chain extensions of another.
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v4.2.0/crates/ink/macro/src/lib.rs#L848-L1280>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.chain_extension.html>.
pub const CHAIN_EXTENSION_DOC_V4: &str = r#"
# Attribute

`#[ink::chain_extension]`

# Description

Defines the interface for a chain extension.

# Structure

The interface consists of an error code that indicates lightweight errors
as well as the definition of some chain extension methods.

The overall structure follows that of a simple Rust trait definition.
The error code is defined as an associated type definition of the trait definition.
The methods are defined as associated trait methods without implementation.

Chain extension methods must not have a `self` receiver such as `&self` or `&mut self`
and must have inputs and output that implement the SCALE encoding and decoding.
Their return value follows specific rules that can be altered using the
`handle_status` attribute which is described in more detail below.

# Usage

Usually the chain extension definition using this procedural macro is provided
by the author of the chain extension in a separate crate.
ink! smart contracts using this chain extension simply depend on this crate
and use its associated environment definition in order to make use of
the methods provided by the chain extension.

# Attributes

There are three different attributes with which the chain extension methods
can be flagged:

| Attribute | Required | Default Value | Description |
|:----------|:--------:|:--------------|:-----------:|
| `ink(extension = N: u32)` | Yes | - | Determines the unique function ID of the chain
extension method. | | `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. |

As with all ink! attributes multiple of them can either appear in a contiguous list:
```
# type Access = i32;
# #[ink::chain_extension]
# pub trait MyChainExtension {
#     type ErrorCode = i32;
#[ink(extension = 5, handle_status = false)]
fn key_access_for_account(key: &[u8], account: &[u8]) -> Access;
# }
```
…or as multiple stand alone ink! attributes applied to the same item:
```
# type Access = i32;
# #[ink::chain_extension]
# pub trait MyChainExtension {
#     type ErrorCode = i32;
#[ink(extension = 5)]
#[ink(handle_status = false)]
fn key_access_for_account(key: &[u8], account: &[u8]) -> Access;
# }
```

## Details: `handle_status`

Default value: `true`

By default all chain extension methods should return a `Result<T, E>` where `E:
From<Self::ErrorCode>`. The `Self::ErrorCode` represents the error code of the chain
extension. This means that a smart contract calling such a chain extension method
first queries the returned status code of the chain extension method and only loads
and decodes the output if the returned status code indicates a successful call.
This design was chosen as it is more efficient when no output besides the error
code is required for a chain extension call. When designing a chain extension try to
utilize the error code to return errors and only use the output buffer for information
that does not fit in a single `u32` value.

A chain extension method that is flagged with `handle_status = false` assumes that the
returned error code will always indicate success. Therefore it will always load and
decode the output buffer and loses the `E: From<Self::ErrorCode>` constraint for the
call.

Note that if a chain extension method does not return `Result<T, E>` where `E:
From<Self::ErrorCode>` but `handle_status = true` it will still return a value of type
`Result<T, Self::ErrorCode>`.

## Usage: `handle_status`

Use both `handle_status = false` and non-`Result<T, E>` return type for the same chain
extension method if a call to it may never fail and never returns a `Result` type.

# Combinations

Due to the possibility to flag a chain extension method with `handle_status` and
return or not `Result<T, E>` there are 4 different cases with slightly varying
semantics:

| `handle_status` | Returns `Result<T, E>` | Effects |
|:---------------:|:----------------:|:--------|
| `true`  | `true`  | The chain extension method is required to return a value of type
`Result<T, E>` where `E: From<Self::ErrorCode>`. A call will always check if the
returned status code indicates success and only then will load and decode the value in
the output buffer. | | `true`  | `false` | The chain extension method may return any
non-`Result` type. A call will always check if the returned status code indicates
success and only then will load and decode the value in the output buffer. The actual
return type of the chain extension method is still `Result<T, Self::ErrorCode>` when
the chain extension method was defined to return a value of type `T`. | | `false` |
`true`  | The chain extension method is required to return a value of type `Result<T,
E>`. A call will always assume that the returned status code indicates success and
therefore always load and decode the output buffer directly. | | `false` | `false` |
The chain extension method may return any non-`Result` type. A call will always assume
that the returned status code indicates success and therefore always load and decode
the output buffer directly. |

# Error Code

Every chain extension defines exactly one `ErrorCode` using the following syntax:

```
#[ink::chain_extension]
pub trait MyChainExtension {
     type ErrorCode = MyErrorCode;

     // more definitions
}
```

The defined `ErrorCode` must implement `FromStatusCode` which should be implemented as
a more or less trivial conversion from the `u32` status code to a `Result<(),
Self::ErrorCode>`. The `Ok(())` value indicates that the call to the chain extension
method was successful.

By convention an error code of `0` represents success.
However, chain extension authors may use whatever suits their needs.

# Example: Definition

In the below example a chain extension is defined that allows its users to read and
write from and to the runtime storage using access privileges:

```
/// Custom chain extension to read to and write from the runtime.
#[ink::chain_extension]
pub trait RuntimeReadWrite {
     type ErrorCode = ReadWriteErrorCode;

     /// Reads from runtime storage.
     ///
     /// # Note
     ///
     /// Actually returns a value of type `Result<Vec<u8>, Self::ErrorCode>`.
     #[ink(extension = 1)]
     fn read(key: &[u8]) -> Vec<u8>;

     /// Reads from runtime storage.
     ///
     /// Returns the number of bytes read and up to 32 bytes of the
     /// read value. Unused bytes in the output are set to 0.
     ///
     /// # Errors
     ///
     /// If the runtime storage cell stores a value that requires more than
     /// 32 bytes.
     ///
     /// # Note
     ///
     /// This requires `ReadWriteError` to implement `From<ReadWriteErrorCode>`
     /// and may potentially return any `Self::ErrorCode` through its return value.
     #[ink(extension = 2)]
     fn read_small(key: &[u8]) -> Result<(u32, [u8; 32]), ReadWriteError>;

     /// Writes into runtime storage.
     ///
     /// # Note
     ///
     /// Actually returns a value of type `Result<(), Self::ErrorCode>`.
     #[ink(extension = 3)]
     fn write(key: &[u8], value: &[u8]);

     /// Returns the access allowed for the key for the caller.
     ///
     /// # Note
     ///
     /// Assumes to never fail the call and therefore always returns `Option<Access>`.
     #[ink(extension = 4, handle_status = false)]
     fn access(key: &[u8]) -> Option<Access>;

     /// Unlocks previously aquired permission to access key.
     ///
     /// # Errors
     ///
     /// If the permission was not granted.
     ///
     /// # Note
     ///
     /// Assumes the call to never fail and therefore does _NOT_ require `UnlockAccessError`
     /// to implement `From<Self::ErrorCode>` as in the `read_small` method above.
     #[ink(extension = 5, handle_status = false)]
     fn unlock_access(key: &[u8], access: Access) -> Result<(), UnlockAccessError>;
}
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteErrorCode {
#     InvalidKey,
#     CannotWriteToKey,
#     CannotReadFromKey,
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteError {
#     ErrorCode(ReadWriteErrorCode),
#     BufferTooSmall { required_bytes: u32 },
# }
# impl From<ReadWriteErrorCode> for ReadWriteError {
#     fn from(error_code: ReadWriteErrorCode) -> Self {
#         Self::ErrorCode(error_code)
#     }
# }
# impl From<scale::Error> for ReadWriteError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub struct UnlockAccessError {
#     reason: String,
# }
# impl From<scale::Error> for UnlockAccessError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum Access {
#     ReadWrite,
#     ReadOnly,
#     WriteOnly,
# }
# impl ink_env::chain_extension::FromStatusCode for ReadWriteErrorCode {
#     fn from_status_code(status_code: u32) -> Result<(), Self> {
#         match status_code {
#             0 => Ok(()),
#             1 => Err(Self::InvalidKey),
#             2 => Err(Self::CannotWriteToKey),
#             3 => Err(Self::CannotReadFromKey),
#             _ => panic!("encountered unknown status code"),
#         }
#     }
# }
```

All the error types and other utility types used in the chain extension definition
above are often required to implement various traits such as SCALE's `Encode` and
`Decode` as well as `scale-info`'s `TypeInfo` trait.

A full example of the above chain extension definition can be seen
[here](https://github.com/paritytech/ink/blob/017f71d60799b764425334f86b732cc7b7065fe6/crates/lang/macro/tests/ui/chain_extension/simple.rs).

# Example: Environment

In order to allow ink! smart contracts to use the above defined chain extension it
needs to be integrated into an `Environment` definition as shown below:

```
# type RuntimeReadWrite = i32;
#
use ink_env::{
     DefaultEnvironment,
     Environment,
};

pub enum CustomEnvironment {}

impl Environment for CustomEnvironment {
     const MAX_EVENT_TOPICS: usize =
         <DefaultEnvironment as Environment>::MAX_EVENT_TOPICS;

     type AccountId = <DefaultEnvironment as Environment>::AccountId;
     type Balance = <DefaultEnvironment as Environment>::Balance;
     type Hash = <DefaultEnvironment as Environment>::Hash;
     type BlockNumber = <DefaultEnvironment as Environment>::BlockNumber;
     type Timestamp = <DefaultEnvironment as Environment>::Timestamp;

     type ChainExtension = RuntimeReadWrite;
}
```

Above we defined the `CustomEnvironment` which defaults to ink!'s `DefaultEnvironment`
for all constants and types but the `ChainExtension` type which is assigned to our
newly defined chain extension.

# Example: Usage

An ink! smart contract can use the above defined chain extension through the
`Environment` definition defined in the last example section using the `env` macro
parameter as shown below.

Note that chain extension methods are accessible through `Self::extension()` or
`self.extension()`. For example as in `Self::extension().read(...)` or
`self.extension().read(...)`.

```
#[ink::contract(env = CustomEnvironment)]
mod read_writer {
     #[ink(storage)]
     pub struct ReadWriter {}

     impl ReadWriter {
         #[ink(constructor)]
         pub fn new() -> Self { Self {} }

         #[ink(message)]
         pub fn read(&self, key: Vec<u8>) -> Result<Vec<u8>, ReadWriteErrorCode> {
             self.env()
                 .extension()
                 .read(&key)
         }

         #[ink(message)]
         pub fn read_small(&self, key: Vec<u8>) -> Result<(u32, [u8; 32]), ReadWriteError> {
             self.env()
                 .extension()
                 .read_small(&key)
         }

         #[ink(message)]
         pub fn write(
             &self,
             key: Vec<u8>,
             value: Vec<u8>,
         ) -> Result<(), ReadWriteErrorCode> {
             self.env()
                 .extension()
                 .write(&key, &value)
         }

         #[ink(message)]
         pub fn access(&self, key: Vec<u8>) -> Option<Access> {
             self.env()
                 .extension()
                 .access(&key)
         }

         #[ink(message)]
         pub fn unlock_access(&self, key: Vec<u8>, access: Access) -> Result<(), UnlockAccessError> {
             self.env()
                 .extension()
                 .unlock_access(&key, access)
         }
     }
# /// Custom chain extension to read to and write from the runtime.
# #[ink::chain_extension]
# pub trait RuntimeReadWrite {
#     type ErrorCode = ReadWriteErrorCode;
#     #[ink(extension = 1)]
#     fn read(key: &[u8]) -> Vec<u8>;
#     #[ink(extension = 2)]
#     fn read_small(key: &[u8]) -> Result<(u32, [u8; 32]), ReadWriteError>;
#     #[ink(extension = 3)]
#     fn write(key: &[u8], value: &[u8]);
#     #[ink(extension = 4, handle_status = false)]
#     fn access(key: &[u8]) -> Option<Access>;
#     #[ink(extension = 5, handle_status = false)]
#     fn unlock_access(key: &[u8], access: Access) -> Result<(), UnlockAccessError>;
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteErrorCode {
#     InvalidKey,
#     CannotWriteToKey,
#     CannotReadFromKey,
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum ReadWriteError {
#     ErrorCode(ReadWriteErrorCode),
#     BufferTooSmall { required_bytes: u32 },
# }
# impl From<ReadWriteErrorCode> for ReadWriteError {
#     fn from(error_code: ReadWriteErrorCode) -> Self {
#         Self::ErrorCode(error_code)
#     }
# }
# impl From<scale::Error> for ReadWriteError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub struct UnlockAccessError {
#     reason: String,
# }
# impl From<scale::Error> for UnlockAccessError {
#     fn from(_: scale::Error) -> Self {
#         panic!("encountered unexpected invalid SCALE encoding")
#     }
# }
# #[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
# pub enum Access {
#     ReadWrite,
#     ReadOnly,
#     WriteOnly,
# }
# impl ink_env::chain_extension::FromStatusCode for ReadWriteErrorCode {
#     fn from_status_code(status_code: u32) -> Result<(), Self> {
#         match status_code {
#             0 => Ok(()),
#             1 => Err(Self::InvalidKey),
#             2 => Err(Self::CannotWriteToKey),
#             3 => Err(Self::CannotReadFromKey),
#             _ => panic!("encountered unknown status code"),
#         }
#     }
# }
# pub enum CustomEnvironment {}
# impl ink_env::Environment for CustomEnvironment {
#     const MAX_EVENT_TOPICS: usize =
#         <ink_env::DefaultEnvironment as ink_env::Environment>::MAX_EVENT_TOPICS;
#
#     type AccountId = <ink_env::DefaultEnvironment as ink_env::Environment>::AccountId;
#     type Balance = <ink_env::DefaultEnvironment as ink_env::Environment>::Balance;
#     type Hash = <ink_env::DefaultEnvironment as ink_env::Environment>::Hash;
#     type BlockNumber = <ink_env::DefaultEnvironment as ink_env::Environment>::BlockNumber;
#     type Timestamp = <ink_env::DefaultEnvironment as ink_env::Environment>::Timestamp;
#
#     type ChainExtension = RuntimeReadWrite;
# }
}
```

# Technical Limitations

- Due to technical limitations it is not possible to refer to the `ErrorCode`
   associated type using `Self::ErrorCode` anywhere within the chain extension and its
   defined methods. Instead chain extension authors should directly use the error code
   type when required. This limitation might be lifted in future versions of ink!.
- It is not possible to declare other chain extension traits as super traits or super
   chain extensions of another.
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v4.2.0/crates/ink/macro/src/lib.rs#L90-L520>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.contract.html>.
pub const CONTRACT_DOC: &str = r#"
# Attribute

`#[ink::contract]`

# Description

Entry point for writing ink! smart contracts.

If you are a beginner trying to learn ink! we recommend you to check out
our extensive [ink! workshop](https://docs.substrate.io/tutorials/v3/ink-workshop/pt1).

# Description

The macro does analysis on the provided smart contract code and generates
proper code.

ink! smart contracts can compile in several different modes.
There are two main compilation models using either
- on-chain mode: `no_std` and WebAssembly as target
- off-chain mode: `std`

We generally use the on-chain mode for actual smart contract instantiation
whereas we use the off-chain mode for smart contract testing using the
off-chain environment provided by the `ink_env` crate.

# Usage

## Header Arguments

The `#[ink::contract]` macro can be provided with some additional comma-separated
header arguments:

- `keep_attr: String`

     Tells the ink! code generator which attributes should be passed to call builders.
     Call builders are used to doing cross-contract calls and are automatically
     generated for contracts.

     **Usage Example:**
     ```
     #[ink::contract(keep_attr = "foo, bar")]
     mod my_contract {
         # #[ink(storage)]
         # pub struct MyStorage;
         # impl MyStorage {
         #     #[ink(constructor)]
         //    #[bar]
         #     pub fn construct() -> Self { MyStorage {} }
         #     #[ink(message)]
         //    #[foo]
         #     pub fn message(&self) {}
         # }
         // ...
     }
     ```

     **Allowed attributes by default:** `cfg`, `cfg_attr`, `allow`, `warn`, `deny`,
`forbid`,         `deprecated`, `must_use`, `doc`, `rustfmt`.

- `env: impl Environment`

     Tells the ink! code generator which environment to use for the ink! smart
contract.     The environment must implement the `Environment` (defined in `ink_env`)
trait and provides     all the necessary fundamental type definitions for `Balance`,
`AccountId` etc.

     When using a custom `Environment` implementation for a smart contract all types
     that it exposes to the ink! smart contract and the mirrored types used in the
runtime     must be aligned with respect to SCALE encoding and semantics.

     **Usage Example:**

     Given a custom `Environment` implementation:
     ```
     pub struct MyEnvironment;

     impl ink_env::Environment for MyEnvironment {
         const MAX_EVENT_TOPICS: usize = 3;
         type AccountId = [u8; 16];
         type Balance = u128;
         type Hash = [u8; 32];
         type Timestamp = u64;
         type BlockNumber = u32;
         type ChainExtension = ::ink::env::NoChainExtension;
     }
     ```
     A user might implement their ink! smart contract using the above custom
`Environment`     implementation as demonstrated below:
     ```
     #[ink::contract(env = MyEnvironment)]
     mod my_contract {
         # pub struct MyEnvironment;
         #
         # impl ink_env::Environment for MyEnvironment {
         #     const MAX_EVENT_TOPICS: usize = 3;
         #     type AccountId = [u8; 16];
         #     type Balance = u128;
         #     type Hash = [u8; 32];
         #     type Timestamp = u64;
         #     type BlockNumber = u32;
         #     type ChainExtension = ::ink::env::NoChainExtension;
         # }
         #
         # #[ink(storage)]
         # pub struct MyStorage;
         # impl MyStorage {
         #     #[ink(constructor)]
         #     pub fn construct() -> Self { MyStorage {} }
         #     #[ink(message)]
         #     pub fn message(&self) {}
         # }
         // ...
     }
     ```

     **Default value:** `DefaultEnvironment` defined in `ink_env` crate.

## Analysis

The `#[ink::contract]` macro fully analyses its input smart contract
against invalid arguments and structure.

Some example rules include but are not limited to:

- There must be exactly one `#[ink(storage)]` struct.

     This struct defines the layout of the storage that the ink! smart contract
operates on.     The user is able to use a variety of built-in facilities, combine
them in various ways     or even provide their own implementations of storage data
structures.

     For more information visit the `ink::storage` crate documentation.

     **Example:**

     ```
     #[ink::contract]
     mod flipper {
         #[ink(storage)]
         pub struct Flipper {
             value: bool,
         }
         # impl Flipper {
         #     #[ink(constructor)]
         #     pub fn construct() -> Self { Flipper { value: false } }
         #     #[ink(message)]
         #     pub fn message(&self) {}
         # }
     }
     ```

- There must be at least one `#[ink(constructor)]` defined method.

     Methods flagged with `#[ink(constructor)]` are special in that they are
dispatchable     upon contract instantiation. A contract may define multiple such
constructors which     allow users of the contract to instantiate a contract in
multiple different ways.

     **Example:**

     Given the `Flipper` contract definition above we add an `#[ink(constructor)]`
     as follows:

     ```
     # #[ink::contract]
     # mod flipper {
         # #[ink(storage)]
         # pub struct Flipper {
         #     value: bool,
         # }
     impl Flipper {
         #[ink(constructor)]
         pub fn new(initial_value: bool) -> Self {
             Flipper { value: false }
         }
         # #[ink(message)]
         # pub fn message(&self) {}
     }
     # }
     ```

- There must be at least one `#[ink(message)]` defined method.

     Methods flagged with `#[ink(message)]` are special in that they are dispatchable
     upon contract invocation. The set of ink! messages defined for an ink! smart
contract     define its API surface with which users are allowed to interact.

     An ink! smart contract can have multiple such ink! messages defined.

     **Note:**

     - An ink! message with a `&self` receiver may only read state whereas an ink!
       message with a `&mut self` receiver may mutate the contract's storage.

     **Example:**

     Given the `Flipper` contract definition above we add some `#[ink(message)]`
definitions     as follows:

     ```
     # #[ink::contract]
     # mod flipper {
         # #[ink(storage)]
         # pub struct Flipper {
         #     value: bool,
         # }
     impl Flipper {
         # #[ink(constructor)]
         # pub fn new(initial_value: bool) -> Self {
         #     Flipper { value: false }
         # }
         /// Flips the current value.
         #[ink(message)]
         pub fn flip(&mut self) {
             self.value = !self.value;
         }

         /// Returns the current value.
         #[ink(message)]
         pub fn get(&self) -> bool {
             self.value
         }
     }
     # }
     ```

     **Payable Messages:**

     An ink! message by default will reject calls that additional fund the smart
contract.     Authors of ink! smart contracts can make an ink! message payable by
adding the `payable`     flag to it. An example below:

     Note that ink! constructors are always implicitly payable and thus cannot be
flagged     as such.

     ```
     # #[ink::contract]
     # mod flipper {
         # #[ink(storage)]
         # pub struct Flipper {
         #     value: bool,
         # }
     impl Flipper {
         # #[ink(constructor)]
         # pub fn new(initial_value: bool) -> Self {
         #     Flipper { value: false }
         # }
         /// Flips the current value.
         #[ink(message)]
         #[ink(payable)] // You can either specify payable out-of-line.
         pub fn flip(&mut self) {
             self.value = !self.value;
         }

         /// Returns the current value.
         #[ink(message, payable)] // ...or specify payable inline.
         pub fn get(&self) -> bool {
             self.value
         }
     }
     # }
     ```

     **Controlling the messages selector:**

     Every ink! message and ink! constructor has a unique selector with which the
     message or constructor can be uniquely identified within the ink! smart contract.
     These selectors are mainly used to drive the contract's dispatch upon calling it.

     An ink! smart contract author can control the selector of an ink! message or ink!
     constructor using the `selector` flag. An example is shown below:

     ```
     # #[ink::contract]
     # mod flipper {
         # #[ink(storage)]
         # pub struct Flipper {
         #     value: bool,
         # }
     impl Flipper {
         #[ink(constructor)]
         #[ink(selector = 0xDEADBEEF)] // Works on constructors as well.
         pub fn new(initial_value: bool) -> Self {
             Flipper { value: false }
         }

         /// Flips the current value.
         #[ink(message)]
         #[ink(selector = 0xCAFEBABE)] // You can either specify selector out-of-line.
         pub fn flip(&mut self) {
             self.value = !self.value;
         }

         /// Returns the current value.
         #[ink(message, selector = 0xFEEDBEEF)] // ...or specify selector inline.
         pub fn get(&self) -> bool {
             self.value
         }
     }
     # }
     ```

## Interacting with the Contract Executor

The `ink_env` crate provides facilities to interact with the contract executor that
connects ink! smart contracts with the outer world.

For example it is possible to query the current call's caller via:
```
# ink_env::test::run_test::<ink_env::DefaultEnvironment, _>(|_| {
let caller = ink_env::caller::<ink_env::DefaultEnvironment>();
# let _caller = caller;
# Ok(())
# }).unwrap();
```

However, ink! provides a much simpler way to interact with the contract executor
via its environment accessor. An example below:

```
#[ink::contract]
mod greeter {
     use ink_env::debug_println;

     #[ink(storage)]
     pub struct Greeter;

     impl Greeter {
         #[ink(constructor)]
         pub fn new() -> Self {
             let caller = Self::env().caller();
             debug_println!("thanks for instantiation {:?}", caller);
             Greeter {}
         }

         #[ink(message, payable)]
         pub fn fund(&self) {
             let caller = self.env().caller();
             let value = self.env().transferred_value();
             debug_println!("thanks for the funding of {:?} from {:?}", value, caller);
         }
     }
}
```

## Events

An ink! smart contract may define events that it can emit during contract execution.
Emitting events can be used by third party tools to query information about a
contract's execution and state.

The following example ink! contract shows how an event `Transferred` is defined and
emitted in the `#[ink(constructor)]`.

```
#[ink::contract]
mod erc20 {
     /// Defines an event that is emitted every time value is transferred.
     #[ink(event)]
     pub struct Transferred {
         from: Option<AccountId>,
         to: Option<AccountId>,
         value: Balance,
     }

     #[ink(storage)]
     pub struct Erc20 {
         total_supply: Balance,
         // more fields...
     }

     impl Erc20 {
         #[ink(constructor)]
         pub fn new(initial_supply: Balance) -> Self {
             let caller = Self::env().caller();
             Self::env().emit_event(Transferred {
                 from: None,
                 to: Some(caller),
                 value: initial_supply,
             });
             Self {
                 total_supply: initial_supply,
             }
         }

         #[ink(message)]
         pub fn total_supply(&self) -> Balance {
             self.total_supply
         }
     }
}
```

## Example: Flipper

The below code shows the complete implementation of the so-called Flipper
ink! smart contract.
For us it acts as the "Hello, World!" of the ink! smart contracts because
it is minimal while still providing some more or less useful functionality.

It controls a single `bool` value that can be either `false` or `true`
and allows the user to flip this value using the `Flipper::flip` message
or retrieve the current value using `Flipper::get`.

```
#[ink::contract]
pub mod flipper {
     #[ink(storage)]
     pub struct Flipper {
         value: bool,
     }

     impl Flipper {
         /// Creates a new flipper smart contract initialized with the given value.
         #[ink(constructor)]
         pub fn new(init_value: bool) -> Self {
             Self { value: init_value }
         }

         /// Flips the current value of the Flipper's boolean.
         #[ink(message)]
         pub fn flip(&mut self) {
             self.value = !self.value;
         }

         /// Returns the current value of the Flipper's boolean.
         #[ink(message)]
         pub fn get(&self) -> bool {
             self.value
         }
     }
}
```
"#;

/// # References
///
/// - <https://github.com/use-ink/ink/blob/5174b68007c91bd44440c73a98a15c5009a0143b/crates/ink/macro/src/lib.rs#L662-L812>
/// - <https://github.com/use-ink/ink/blob/5174b68007c91bd44440c73a98a15c5009a0143b/crates/ink/macro/src/contract_ref.rs>
/// - <https://use.ink/docs/v6/macros-attributes/contract_ref>
pub const CONTRACT_REF_DOC: &str = r#"
# Attribute

`#[ink::contract]`

# Description

Defines the interface of a "callee" contract and generates a wrapper type which can be
used for interacting with the contract.

The interface is defined using a trait, and the macro generates a native Rust type
(a contract reference) that implements this trait, so it can be used in any Rust
context that expects types.

## Example

### Definition

```rust
#[ink::contract_ref(abi = "sol")]
pub trait Erc20 {
    Returns the total supply of the ERC-20 smart contract.
    #[ink(message)]
    fn total_supply(&self) -> ink::U256;

    Transfers balance from the caller to the given address.
    #[ink(message)]
    fn transfer(&mut self, amount: ink::U256, to: ink::Address) -> bool;

    // etc.
}
```

### Usage

Given the above interface, you can use the generated contract reference in a
"caller" contract as shown below:

```rust
#[ink::contract]
mod erc20_caller {
    use ink::U256;

    #[ink(storage)]
    pub struct Erc20Caller {
        callee: ink::Address,
    }

    impl Erc20Caller {
        #[ink(constructor)]
        pub fn new(addr: ink::Address) -> Self {
            Self { callee: addr }
        }

        #[ink(message)]
        pub fn call_erc20(&self) {
            // Calls the ERC20 contract using the contract ref generated above.
            let total = Erc20Ref::from(self.callee).total_supply();

            // Do some fun stuff!
        }
    }
}
```

## Header Arguments

The `#[ink::contract_ref]` macro can be provided with some additional
comma-separated header arguments:

### `abi: String`

Specifies the ABI (Application Binary Interface) of the "callee" contract.

**Usage Example:**
```rust
#[ink::contract_ref(abi = "sol")]
pub trait Callee {
  #[ink(message)]
  fn message1(&self);

  #[ink(message, selector = 42)]
  fn message2(&self);
}
```

**Default value:** Empty.

**Allowed values:** `"ink"`, `"sol"`

**NOTE**: When no value is provided, the generated contract reference will use the
ABI of the  root contract (i.e "ink" in "ink" and "all" ABI mode and "sol" in "sol" ABI mode).

### `env: impl Environment`

Specifies the environment to use for the generated contract reference.

This should be the same environment used by the root contract (if any).

The environment must implement the `Environment` (defined in `ink_env`)
trait and provides all the necessary fundamental type definitions for `Balance`,
`AccountId` etc.

**Usage Example:**

Given a custom `Environment` implementation:
```rust
#[derive(Clone)]
pub struct MyEnvironment;

impl ink_env::Environment for MyEnvironment {
  const NATIVE_TO_ETH_RATIO: u32 = 100_000_000;
  type AccountId = [u8; 16];
  type Balance = u128;
  type Hash = [u8; 32];
  type Timestamp = u64;
  type BlockNumber = u32;
  type EventRecord = ();
}
```
A user might define an interface (and generate a contract reference) that uses the
above custom `Environment` implementation as demonstrated below:
```rust
#[ink::contract_ref(env = MyEnvironment)]
pub trait Callee {
  #[ink(message)]
  fn message(&self);

  // ...
}
```

**Default value:** `DefaultEnvironment` defined in `ink_env` crate.
"#;

/// # References
///
/// - <https://github.com/use-ink/ink/blob/master/crates/ink/macro/src/lib.rs#L1641-L1676>
/// - <https://github.com/use-ink/ink/blob/v6.0.0-alpha.4/crates/ink/macro/src/error.rs>
/// - <https://use.ink/docs/v6/macros-attributes/error/>
pub const ERROR_DOC: &str = r#"
# Attribute

`#[ink::error]`

# Description

Applicable on `struct` and `enum` definitions.

It derives traits necessary for encoding/decoding a custom type as revert error data.

The following traits are derived depending on the ABI mode:
- In "ink" and "all" ABI mode:
  - `scale::Encode` and `scale::Decode` for encoding/decoding ink! revert error data
  - `scale_info::TypeInfo` for generating ink! contract metadata (gated behind the `std` feature)
- In "sol" and "all" ABI mode:
  - `SolErrorEncode` and `SolErrorDecode`
    for encoding/decoding custom types as Solidity custom errors
  - `SolErrorMetadata` for generating Solidity ABI metadata (gated behind the `std` feature)

## Example

```rust
#[ink::error]
struct UnitError;

#[ink::error]
enum MultipleErrors {
    UnitError,
    ErrorWithParams(bool, u8, String),
    ErrorWithNamedParams {
        status: bool,
        count: u8,
        reason: String,
    }
}
```
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v5.0.0-rc.1/crates/ink/macro/src/lib.rs#L656-L692>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.event.html>.
pub const EVENT_DOC: &str = r#"
# Attribute

`#[ink::event]`

# Description

Implements the necessary traits for a `struct` to be emitted as an event from a
contract.

By default, a signature topic will be generated for the event. This allows consumers
to filter and identify events of this type. Marking an event with `anonymous`
means no signature topic will be generated or emitted.
Custom signature topic can be specified with `signature_topic = <32 byte hex string>`.

`signature_topic` and `anonymous` are conflicting arguments.

# Examples

```
#[ink::event]
pub struct MyEvent {
    pub field: u32,
    #[ink(topic)]
    pub topic: [u8; 32],
}

// Setting `anonymous` means no signature topic will be emitted for the event.
#[ink::event(anonymous)]
pub struct MyAnonEvent {
    pub field: u32,
    #[ink(topic)]
    pub topic: [u8; 32],
}
// Setting `signature_topic = <hex_string>` specifies custom signature topic.
#[ink::event(
    signature_topic = "1111111111111111111111111111111111111111111111111111111111111111"
)]
pub struct MyCustomSignatureEvent {
    pub field: u32,
    #[ink(topic)]
    pub topic: [u8; 32],
}
```
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v5.0.0-rc.1/crates/ink/macro/src/lib.rs#L1598-L1625>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.scale_derive.html>.
pub const SCALE_DERIVE_DOC: &str = r#"
# Attribute

`#[ink::scale_derive]`

# Description

Derive the re-exported traits `ink::scale::Encode`, `ink::scale::Decode` and
`ink::scale_info::TypeInfo`. It enables using the built in derive macros for these
traits without depending directly on the `parity-scale-codec` and `scale-info` crates.

# Options
  - `Encode`: derives `ink::scale::Encode`
  - `Decode`: derives `ink::scale::Decode`
  - `TypeInfo`: derives `ink::scale_info::TypeInfo`

# Examples

```
#[ink::scale_derive(Encode, Decode, TypeInfo)]
pub enum Error {}
```
This is a convenience macro that expands to include the additional `crate` attributes
required for the path of the re-exported crates.

```
#[derive(::ink::scale::Encode, ::ink::scale::Decode)]
#[codec(crate = ::ink::scale)]
#[cfg_attr(
  feature = "std",
  derive(::scale_info::TypeInfo),
  scale_info(crate = ::ink::scale_info)
)]
pub enum Error {}
```
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v4.2.0/crates/ink/macro/src/lib.rs#L649-L803>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.storage_item.html>.
pub const STORAGE_ITEM_DOC: &str = r#"
# Attribute

`#[ink::storage_item]`

# Description

Prepares the type to be fully compatible and usable with the storage.
It implements all necessary traits and calculates the storage key for types.
`Packed` types don't have a storage key, but non-packed types (like `Mapping`, `Lazy`
etc.) require calculating the storage key during compilation.

Consider annotating structs and enums that are intended to be a part of
the storage with this macro. If the type is packed then the usage of the
macro is optional.

If the type is non-packed it is best to rely on automatic storage key
calculation via `ink::storage_item`.

The usage of `KEY: StorageKey` generic allows to propagate the parent's storage key to
the type and offset the storage key of the type. It is helpful for non-packed types
that can be used several times in the contract. Each field should have a unique
storage key, so propagation of the parent's storage key allows one to achieve it.

The macro should be called before `derive` macros because it can change the type.

All required traits can be:
- Derived manually via `#[derive(...)]`.
- Derived automatically via deriving of `scale::Decode` and `scale::Encode`.
- Derived via this macro.

# Example

## Trait implementation

```
use ink_prelude::vec::Vec;
use ink::storage::{
     Lazy,
     Mapping,
};
use ink::storage::traits::{
     StorageKey,
     StorableHint,
};
use ink::storage::traits::Storable;

// Deriving `scale::Decode` and `scale::Encode` also derives blanket implementation of all
// required traits to be storable.
#[derive(scale::Decode, scale::Encode)]
#[cfg_attr(
     feature = "std",
     derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
#[derive(Default, Debug)]
struct Packed {
     s1: u128,
     s2: Vec<u128>,
     // Fails because `StorableHint` is only implemented for `Vec` where `T: Packed`.
     // s3: Vec<NonPacked>,
}

// Example of how to define the packed type with generic.
#[derive(scale::Decode, scale::Encode)]
#[cfg_attr(
     feature = "std",
     derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
#[derive(Default, Debug)]
struct PackedGeneric<T: ink::storage::traits::Packed> {
     s1: (u128, bool),
     s2: Vec<T>,
     s3: String,
}

// Example of how to define the non-packed type.
#[ink::storage_item]
#[derive(Default, Debug)]
struct NonPacked {
     s1: Mapping<u32, u128>,
     s2: Lazy<u128>,
}

// Example of how to define the non-packed generic type.
#[ink::storage_item(derive = false)]
#[derive(Storable, StorableHint, StorageKey)]
#[cfg_attr(
     feature = "std",
     derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
#[derive(Default, Debug)]
struct NonPackedGeneric<T>
where
     T: Default + core::fmt::Debug,
     T: ink::storage::traits::Packed,
{
     s1: u32,
     s2: T,
     s3: Mapping<u128, T>,
}

// Example of how to define a complex packed type.
#[derive(scale::Decode, scale::Encode)]
#[cfg_attr(
     feature = "std",
     derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout)
)]
#[derive(Default, Debug)]
struct PackedComplex {
     s1: u128,
     s2: Vec<u128>,
     s3: Vec<Packed>,
}

// Example of how to define a complex non-packed type.
#[ink::storage_item]
#[derive(Default, Debug)]
struct NonPackedComplex<KEY: StorageKey> {
     s1: (String, u128, Packed),
     s2: Mapping<u128, u128>,
     s3: Lazy<u128>,
     s4: Mapping<u128, Packed>,
     s5: Lazy<NonPacked>,
     s6: PackedGeneric<Packed>,
     s7: NonPackedGeneric<Packed>,
     // Fails because: the trait `ink::storage::traits::Packed` is not implemented for `NonPacked`
     // s8: Mapping<u128, NonPacked>,
}
```

## Header Arguments

The `#[ink::storage_item]` macro can be provided with an additional comma-separated
header argument:

- `derive: bool`

     The `derive` configuration parameter is used to enable/disable auto deriving of
     all required storage traits.

     **Usage Example:**
     ```
     use ink::storage::Mapping;
     use ink::storage::traits::{
         StorableHint,
         StorageKey,
         Storable,
     };

     #[ink::storage_item(derive = false)]
     #[derive(StorableHint, Storable, StorageKey)]
     struct NonPackedGeneric<T: ink::storage::traits::Packed> {
         s1: u32,
         s2: Mapping<u128, T>,
     }
     ```

     **Default value:** true.
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v4.2.0/crates/ink/macro/src/lib.rs#L805-L846>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.test.html>.
pub const TEST_DOC: &str = r#"
# Attribute

`#[ink::test]`

# Description

Defines a unit test that makes use of ink!'s off-chain testing capabilities.

If your unit test does not require the existence of an off-chain environment
it is fine to not use this macro since it bears some overhead with the test.

Note that this macro is not required to run unit tests that require ink!'s
off-chain testing capabilities but merely improves code readability.

## How do you find out if your test requires the off-chain environment?

Normally if the test recursively uses or invokes some contract methods that
call a method defined in `self.env()` or `Self::env()`.

An examples is the following:

```no_compile
let caller: AccountId = self.env().caller();
```

# Example

```
#[cfg(test)]
mod tests {
     // Conventional unit test that works with assertions.
     #[ink::test]
     fn test1() {
         // test code comes here as usual
     }

     // Conventional unit test that returns some Result.
     // The test code can make use of operator-`?`.
     #[ink::test]
     fn test2() -> Result<(), ink_env::Error> {
         // test code that returns a Rust Result type
     }
}
```
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v4.2.0/crates/ink/macro/src/lib.rs#L522-L647>.
///
/// Ref: <https://paritytech.github.io/ink/ink/attr.trait_definition.html>.
pub const TRAIT_DEFINITION_DOC: &str = r#"
# Attribute

`#[ink::trait_definition]`

# Description

Marks trait definitions to ink! as special ink! trait definitions.

There are some restrictions that apply to ink! trait definitions that
this macro checks. Also ink! trait definitions are required to have specialized
structure so that the main [`#[ink::contract]`](`macro@crate::contract`) macro can
properly generate code for its implementations.

# Example

# Trait definition:

```
# type Balance = <ink_env::DefaultEnvironment as ink_env::Environment>::Balance;
# type AccountId = <ink_env::DefaultEnvironment as ink_env::Environment>::AccountId;

#[ink::trait_definition]
pub trait Erc20 {
     /// Returns the total supply of the ERC-20 smart contract.
     #[ink(message)]
     fn total_supply(&self) -> Balance;

     /// Transfers balance from the caller to the given address.
     #[ink(message)]
     fn transfer(&mut self, amount: Balance, to: AccountId) -> bool;

     // etc.
}
```

# Trait implementation

Given the above trait definition you can implement it as shown below:

```
#[ink::contract]
mod base_erc20 {
#    // We somehow cannot put the trait in the doc-test crate root due to bugs.
#    #[ink::trait_definition]
#    pub trait Erc20 {
#       /// Returns the total supply of the ERC-20 smart contract.
#       #[ink(message)]
#       fn total_supply(&self) -> Balance;
#
#       /// Transfers balance from the caller to the given address.
#       #[ink(message)]
#       fn transfer(&mut self, amount: Balance, to: AccountId) -> bool;
#    }
#
     #[ink(storage)]
     pub struct BaseErc20 {
         total_supply: Balance,
     }

     impl BaseErc20 {
         #[ink(constructor)]
         pub fn new(initial_supply: Balance) -> Self {
             Self { total_supply: initial_supply }
         }
     }

     impl Erc20 for BaseErc20 {
         /// Returns the total supply of the ERC-20 smart contract.
         #[ink(message)]
         fn total_supply(&self) -> Balance {
             self.total_supply
         }

         #[ink(message)]
         fn transfer(&mut self, amount: Balance, to: AccountId) -> bool {
             unimplemented!()
         }
     }
}
```

## Header Arguments

The `#[ink::trait_definition]` macro can be provided with some additional
comma-separated header arguments:

- `namespace: String`

     The namespace configuration parameter is used to influence the generated
     selectors of the ink! trait messages. This is useful to disambiguate
     ink! trait definitions with equal names.

     **Usage Example:**
     ```
     #[ink::trait_definition(namespace = "foo")]
     pub trait TraitDefinition {
         #[ink(message)]
         fn message1(&self);

         #[ink(message, selector = 42)]
         fn message2(&self);
     }
     ```

     **Default value:** Empty.

- `keep_attr: String`

     Tells the ink! code generator which attributes should be passed to call builders.
     Call builders are used to doing cross-contract calls and are automatically
     generated for contracts.

     **Usage Example:**
     ```
     #[ink::trait_definition(keep_attr = "foo, bar")]
     pub trait Storage {
         #[ink(message)]
     //  #[foo]
         fn message1(&self);

         #[ink(message)]
     //  #[bar]
         fn message2(&self);
     }
     ```

     **Allowed attributes by default:** `cfg`, `cfg_attr`, `allow`, `warn`, `deny`,
`forbid`,         `deprecated`, `must_use`, `doc`, `rustfmt`.
"#;

/// Ref: <https://github.com/paritytech/ink/blob/v4.2.0/crates/e2e/macro/src/lib.rs#L28-L94>.
///
/// Ref: <https://paritytech.github.io/ink/ink_e2e/attr.test.html>.
pub const E2E_TEST_DOC: &str = r#"
# Attribute

`#[ink_e2e::test]`

# Description

Defines an End-to-End test.

The system requirements are:

- A Substrate node with `pallet-contracts` installed on the local system. You can e.g.
  use [`substrate-contracts-node`](https://github.com/paritytech/substrate-contracts-node)
  and install it on your PATH, or provide a path to an executable using the
  `CONTRACTS_NODE` environment variable.

Before the test function is invoked the contract will have been build. Any errors
that occur during the contract build will prevent the test function from being
invoked.

## Header Arguments

The `#[ink::e2e_test]` macro can be provided with some additional comma-separated
header arguments:

# Example

```no_compile
# // TODO(#xxx) Remove the `no_compile`.
#[cfg(test)]
mod tests {
    use ::ink_e2e::*;
    type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;

    #[ink::e2e_test]
    async fn e2e_test_2(mut client: ::ink_e2e::Client<C,E>) -> E2EResult<()> {
        // given
        let constructor = contract_transfer::constructors::new();
        let contract_acc_id = client.instantiate(
            &mut ::ink_e2e::alice(),
            constructor,
            1337,
            None,
        )
        .await
        .expect("instantiating contract failed")
        .account_id;

        // when
        let transfer = contract_transfer::messages::give_me(120);
        let call_res = client.call(
            &mut ::ink_e2e::bob(),
            contract_acc_id.clone(),
            transfer.into(),
            10,
            None,
        )
        .await;

        // then
        assert!(call_res.is_ok());
        Ok(())
    }
}
```

You can also use build the `Signer` type yourself, without going through
the pre-defined functions:

```no_compile
let mut bob = ::ink_e2e::PairSigner::new(
    ::ink_e2e::AccountKeyring::Bob.pair()
);
```
"#;