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
53 changes: 53 additions & 0 deletions packages/web/docs/core-schemas/programs/tracing-examples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export const counterIncrement = `name Counter;

storage {
[0] count: uint256;
}

create {
count = 0;
}

code {
count = count + 1;
}`;

export const thresholdCheck = `name ThresholdCounter;

storage {
[0] count: uint256;
[1] threshold: uint256;
}

create {
count = 0;
threshold = 5;
}

code {
count = count + 1;

if (count >= threshold) {
count = 0;
}
}`;

export const multipleStorageSlots = `name MultiSlot;

storage {
[0] a: uint256;
[1] b: uint256;
[2] sum: uint256;
}

create {
a = 10;
b = 20;
sum = 0;
}

code {
sum = a + b;
a = a + 1;
b = b + 1;
}`;
59 changes: 8 additions & 51 deletions packages/web/docs/core-schemas/programs/tracing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ sidebar_position: 4
import SpecLink from "@site/src/components/SpecLink";
import SchemaExample from "@site/src/components/SchemaExample";
import { TracePlayground, TraceExample } from "@theme/ProgramExample";
import {
counterIncrement,
thresholdCheck,
multipleStorageSlots,
} from "./tracing-examples";

# Tracing execution

Expand Down Expand Up @@ -50,19 +55,7 @@ This example shows a basic counter that increments a storage variable:
<TraceExample
title="Counter increment"
description="Increments count from 0 to 1, storing the result"
source={`name Counter;

storage {
[0] count: uint256;
}

create {
count = 0;
}

code {
count = count + 1;
}`}
source={counterIncrement}
/>

### Storage with threshold check
Expand All @@ -72,25 +65,7 @@ This example demonstrates conditional logic with storage variables:
<TraceExample
title="Threshold check"
description="Increments counter and resets when reaching threshold"
source={`name ThresholdCounter;

storage {
[0] count: uint256;
[1] threshold: uint256;
}

create {
count = 0;
threshold = 5;
}

code {
count = count + 1;

if (count >= threshold) {
count = 0;
}
}`}
source={thresholdCheck}
/>

### Multiple storage slots
Expand All @@ -100,25 +75,7 @@ This example shows working with multiple storage locations:
<TraceExample
title="Multiple storage slots"
description="Updates multiple storage values in sequence"
source={`name MultiSlot;

storage {
[0] a: uint256;
[1] b: uint256;
[2] sum: uint256;
}

create {
a = 10;
b = 20;
sum = 0;
}

code {
sum = a + b;
a = a + 1;
b = b + 1;
}`}
source={multipleStorageSlots}
/>

## Trace data structure
Expand Down
Loading