Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contract-dev/gas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ let sizeMsg = computeDataSize(
);

let fwdFee = getForwardFee(
sizeMsg.cells - 1,
sizeMsg.cells - 1,
sizeMsg.bits - msg.toCell().bits(),
isAccountInMasterchain
);
Expand All @@ -157,7 +157,7 @@ In Tolk, both computations can be performed with a call to `msg.send()` with mod

If the size of the outgoing message is bounded by the size of the incoming message, we can estimate the forward fee of an outgoing message to be no larger than the forward fee of the incoming message, that was already computed by TVM. Thus, we don't have to calculate it again. Note that this estimation is correct only for a contract system in the same workchain, because gas prices depend on the workchain.

```tolk
```tolk title="Tolk"
fun onInternalMessage(in: InMessage) {
val fwdFee = in.originalForwardFee;
// ...
Expand All @@ -170,7 +170,7 @@ Assume the contract receives a message with an unknown size and forwards it furt

For this case, in Tolk, there is a function `calculateForwardFeeWithoutLumpPrice()`. In TVM, it's implemented as [`GETFORWARDFEESIMPLE`](/tvm/instructions#f83c-getforwardfeesimple). This function does not take `lumpPrice` into account.

```tolk
```tolk title="Tolk"
fun onInternalMessage(in: InMessage) {
val origFwdFee = in.originalForwardFee;

Expand Down
46 changes: 23 additions & 23 deletions contract-dev/upgrades.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If there's not enough Toncoin to execute action phase with the code update, but

### Example

```tolk expandable
```tolk title="Tolk" expandable
struct (0x1111) UpgradeContract {
data: cell?
code: cell?
Expand All @@ -77,8 +77,8 @@ fun onInternalMessage(in: InMessage) {
}
}

else => {
// just accept TON
else => {
// just accept TON
}
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ The admin can also send `RejectUpgrade` at any time to cancel a pending upgrade.

### Example

```tolk expandable
```tolk title="Tolk" expandable
struct UpgradeContract {
data: cell?
code: cell?
Expand Down Expand Up @@ -171,7 +171,7 @@ fun onInternalMessage(in: InMessage) {

ApproveUpgrade => {
var storage = lazy Storage.load();

assert (in.senderAddress == storage.adminAddress) throw 100;
assert (storage.CurrentRequest != null) throw 301;
assert (storage.CurrentRequest!.timestamp + storage.timeout < blockchain.now()) throw 302;
Expand All @@ -189,8 +189,8 @@ fun onInternalMessage(in: InMessage) {
}
}

else => {
// just accepted tons
else => {
// just accepted tons
}
}
}
Expand Down Expand Up @@ -244,9 +244,9 @@ The key mechanism: `setTvmRegisterC3()` switches the code register so the migrat

The example shows a counter contract that adds a metadata field through a hot upgrade. The storage structure changes: the original version stores only `adminAddress` and `counter`. The new version adds `metadata` and reorders fields.

Original contract (`main.tolk`):
Original contract:

```tolk expandable
```tolk title="main.tolk" expandable
import "@stdlib/tvm-lowlevel"

struct (0x00001111) HotUpgrade {
Expand All @@ -260,7 +260,7 @@ type AllowedMessages =
| HotUpgrade
| IncreaseCounter

// migration function must have method_id
// migration function must have method_id
@method_id(2121)
fun hotUpgradeData(additionalData: cell?) { return null; }

Expand All @@ -273,21 +273,21 @@ fun onInternalMessage(in: InMessage) {
HotUpgrade => {
var storage = lazy Storage.load();
assert (in.senderAddress == storage.adminAddress) throw 1111;

contract.setCodePostponed(msg.code);

setTvmRegisterC3(transformSliceToContinuation(msg.code.beginParse()));
hotUpgradeData(msg.additionalData);
}
}

IncreaseCounter => {
var storage = lazy Storage.load();
storage.counter += 1;
storage.save();
}

else => {
// just accept TON
else => {
// just accept TON
}
}
}
Expand Down Expand Up @@ -317,9 +317,9 @@ The `hotUpgradeData()` function in the original code returns `null` because it d
1. `setTvmRegisterC3()` switches register C3 to the new code immediately
1. `hotUpgradeData(msg.additionalData)` is called and runs with the new code

New contract with migration (`new.tolk`):
New contract with migration:

```tolk
```tolk title="new.tolk"
import "@stdlib/tvm-lowlevel"

struct (0x00001111) HotUpgrade {
Expand All @@ -333,13 +333,13 @@ type AllowedMessages =
| HotUpgrade
| IncreaseCounter

// migration function must have method_id
// migration function must have method_id
@method_id(2121)
fun hotUpgradeData(additionalData: cell?) {
fun hotUpgradeData(additionalData: cell?) {
var oldStorage = lazy oldStorage.load();

assert (additionalData != null) throw 1112;

var storage = Storage {
adminAddress: oldStorage.adminAddress,
counter: oldStorage.counter,
Expand Down Expand Up @@ -368,21 +368,21 @@ fun onInternalMessage(in: InMessage) {
HotUpgrade => {
var storage = lazy Storage.load();
assert (in.senderAddress == storage.adminAddress) throw 1111;

contract.setCodePostponed(msg.code);

setTvmRegisterC3(transformSliceToContinuation(msg.code.beginParse()));
hotUpgradeData(msg.additionalData);
}
}

IncreaseCounter => {
var storage = lazy Storage.load();
storage.counter += 1;
storage.save();
}

else => {
// just accept TON
else => {
// just accept TON
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/api/price.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ take_pool_state#bddd4954 query_id:uint64 reserve0:Coins reserve1:Coins total_sup

Here is a smart contract snippet in [Tolk](/languages/tolk) illustrating how you can send the 'provide' message:

```tolk
```tolk title="Tolk"
struct (0x6e24728d) ProvideDeDustPool {
queryId: uint64
doIncludeAssets: bool
Expand Down
8 changes: 4 additions & 4 deletions foundations/addresses/derive.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The `StateInit` is distinct from the account's current state. It is the initial

If it's known how to compose the contract's initial `code` and `data`, it's enough to follow the general algorithm mentioned above as is. Code and data form a `StateInit`, and the [workchain](/foundations/addresses/overview#workchain-id) is usually hardcoded. Below is one of the most common patterns when `code` is a constant cell known in advance and `data` is composed at runtime.

```tolk expandable
```tolk title="Tolk" expandable
// Compose an address builder
fun calculateAddress(
code: cell,
Expand Down Expand Up @@ -63,7 +63,7 @@ The `calculateAddress` function uses the [`AutoDeployAddress`](/languages/tolk/f

When working with the [contract sharding](/contract-dev/contract-sharding) pattern, child contracts usually have a `StateInit` that depends on the parent. In the example below, the dependence is implemented by adding the parent address to the child `StateInit`. The same logic from the [simple on-chain](#on-chain-simple) case works here, and only `getData` has to be changed.

```tolk expandable
```tolk title="Tolk" expandable
// Compose an address builder using the AutoDeployAddress built-in.
fun calculateAddress(code: cell, data: cell, workchain: int): builder {
val addr = AutoDeployAddress {
Expand Down Expand Up @@ -108,7 +108,7 @@ A [vanity contract](/contract-dev/vanity) allows _customizing_ the address of a

In this case, there is no real correlation between the data the contract holds and its final address. So there is no way to actually _derive_ the address. The only option left is to define a constant with the actual address that is obtained in advance.

```tolk
```tolk title="Tolk"
// Constant address in raw format.
const VANITY_ADDRESS_RAW: address = address("0:4de24b95c1c3c9b6a94231460716192c7d2b4e444ca6ae9a98bc5c4b3fcdef3f");

Expand All @@ -129,7 +129,7 @@ This may seem similar to the [vanity](#on-chain-vanity) case, but it serves a di

The logic here is more similar to the [simple](#on-chain-simple) case. The only difference is the additional `toShard` field.

```tolk expandable
```tolk title="Tolk" expandable
// Compose an address builder using the AutoDeployAddress built-in.
fun deriveAddress(target: address, prefixLength: int): builder {
val code = getCode();
Expand Down
2 changes: 1 addition & 1 deletion foundations/messages/external-out.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ As outbound external messages do not carry any Toncoin value, the price of their

In Tolk, outbound external messages may be composed using the `createExternalLogMessage` function.

```tolk
```tolk title="Tolk"
tolk 1.2

struct(0x10) ValueWasDeposited {
Expand Down
2 changes: 1 addition & 1 deletion standard/tokens/nft/deploy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ To deploy an item from a smart contract, send a message from the contract to the

The following example is a minimal smart contract that only implements the item deployment logic. In real deployments, this is integrated into a larger flow.

```tolk
```tolk title="Tolk"
// SnakeString describes a (potentially long) string inside a cell;
// short strings are stored as-is, like "my-picture.png";
// long strings are nested refs, like "xxxx".ref("yyyy".ref("zzzz"))
Expand Down
2 changes: 1 addition & 1 deletion standard/tokens/nft/nft-2.0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ The TEP-66 standard does not define the body of internal messages used to delive

Below is an example contract snippet written in Tolk:

```tolk
```tolk title="Tolk"
// You should retrieve these values by calling the collection's getter method beforehand
struct Storage {
numerator: uint16
Expand Down
2 changes: 1 addition & 1 deletion tvm/get-method.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PROGRAM{

The above is equivalent to the following Tolk code, which compiles to almost identical Fift code.

```tolk
```tolk title="Tolk"
fun main() { }

get fun get_x(): int {
Expand Down