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
Copy file name to clipboardExpand all lines: docs/src/content/docs/book/contracts.mdx
+47-6Lines changed: 47 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -538,16 +538,15 @@ Read more about them in their dedicated section: [Internal functions](/book/func
538
538
539
539
:::
540
540
541
-
### Converting to Cell or Slice
541
+
### Operations
542
+
543
+
#### Converting to Cell or Slice {#tocellslice}
542
544
543
545
<Badgetext="Available since Tact 1.6.12"variant="tip"size="medium"/><p/>
544
546
545
-
You can convert a contract instance to a [`Cell{:tact}`](/book/cells#cells) or [`Slice{:tact}`](/book/cells#slices) using the `toCell(){:tact}` and `toSlice(){:tact}` methods.
546
-
These methods will build a new `Cell{:tact}` or `Slice{:tact}` with the contract data.
547
+
You can convert a contract instance to a [`Cell{:tact}`][cell] or [`Slice{:tact}`][slice] using the [`toCell(){:tact}`][ct-tc] and [`toSlice(){:tact}`][ct-ts] methods. These methods will build a new `Cell{:tact}` or `Slice{:tact}` with the contract data.
547
548
548
549
```tact
549
-
// ...
550
-
551
550
contract WalletV4(
552
551
seqno: Int as uint32,
553
552
walletId: Int as int32,
@@ -576,7 +575,7 @@ This is useful when you need to explicitly set data of your contract for low lev
576
575
577
576
:::note
578
577
579
-
If a contract doesn't use [contract parameters](/book/contracts#parameters), the resulting `Cell{:tact}` or `Slice{:tact}` will contain a leading one bit representing the [lazy initialization bit](/book/functions/#init).
578
+
If a contract doesn't use [contract parameters](/book/contracts#parameters), the resulting `Cell{:tact}` or `Slice{:tact}` will contain a leading one bit representing the [lazy initialization bit](/book/functions/#init).
580
579
581
580
:::
582
581
@@ -587,8 +586,48 @@ This is useful when you need to explicitly set data of your contract for low lev
587
586
588
587
:::
589
588
589
+
#### Obtaining from Cell or Slice {#fromcellslice}
590
+
591
+
<Badgetext="Available since Tact 1.6.13"variant="tip"size="medium"/><p/>
592
+
593
+
If you have a contract data [`Cell{:tact}`][cell] or [`Slice{:tact}`][slice] with composed using the [`toCell{:tact}` or `toSlice{:tact}` methods](#tocellslice), you can obtain the initial contract [struct](/book/structs-and-messages#structs) back with the respective [`fromCell(){:tact}`][ct-fc] and [`fromSlice(){:tact}`][ct-fs] functions. These functions would parse a given `Cell{:tact}` or `Slice{:tact}` and produce a struct with contract variables.
594
+
595
+
```tact
596
+
contract PointCaller(
597
+
x: Int as uint32,
598
+
y: Int as uint32,
599
+
) {
600
+
receive(msg: NewContractData) {
601
+
let contractStruct = PointCaller.fromCell(msg.cell);
602
+
self.x = contractStruct.x;
603
+
self.y = contractStruct.y;
604
+
}
605
+
606
+
get fun inverseLaw(): Bool {
607
+
let contractStruct = PointCaller.fromCell(self.toCell());
0 commit comments