Skip to content

Commit 43c3f41

Browse files
feat: update scratch storage example
1 parent 0fe0058 commit 43c3f41

File tree

6 files changed

+29
-37
lines changed

6 files changed

+29
-37
lines changed

projects/typescript-examples/contracts/ScratchStorage/contract.algo.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// example: SCRATCH_STORAGE
12
import {
23
abimethod,
34
uint64,
@@ -25,7 +26,6 @@ import { Scratch, gloadBytes, gloadUint64 } from '@algorandfoundation/algorand-t
2526
*/
2627
@contract({ scratchSlots: [0, 1, 2, { from: 10, to: 20 }] }) // This reserves slots 0, 1, 2 and slots 10-20
2728
export default class ScratchStorage extends Contract {
28-
// example: STORE_SCRATCH_VALUES
2929
/**
3030
* Stores values in scratch space
3131
* This method demonstrates how to store different types of values in scratch slots
@@ -36,9 +36,7 @@ export default class ScratchStorage extends Contract {
3636
Scratch.store(2, Uint64(100))
3737
Scratch.store(15, Uint64(999))
3838
}
39-
// example: STORE_SCRATCH_VALUES
4039

41-
// example: LOAD_SCRATCH_VALUES
4240
/**
4341
* Reads values from scratch space
4442
* This method demonstrates how to read different types of values from scratch slots
@@ -55,9 +53,7 @@ export default class ScratchStorage extends Contract {
5553
assert(value2 === 100, 'Value in slot 2 should be 100')
5654
assert(value3 === 999, 'Value in slot 15 should be 999')
5755
}
58-
// example: LOAD_SCRATCH_VALUES
5956

60-
// example: DEMONSTRATE_SCRATCH_STORAGE
6157
/**
6258
* Demonstrates basic scratch storage operations
6359
* @returns true if all operations succeed
@@ -68,9 +64,7 @@ export default class ScratchStorage extends Contract {
6864

6965
return true
7066
}
71-
// example: DEMONSTRATE_SCRATCH_STORAGE
7267

73-
// example: READ_FROM_GROUP_TRANSACTION
7468
/**
7569
* Demonstrates reading values from another transaction in the same group
7670
* @param groupIndex The index of the transaction in the group to read from
@@ -81,9 +75,7 @@ export default class ScratchStorage extends Contract {
8175
public readFromGroupTransaction(groupIndex: uint64, scratchSlot: uint64): uint64 {
8276
return gloadUint64(groupIndex, scratchSlot)
8377
}
84-
// example: READ_FROM_GROUP_TRANSACTION
8578

86-
// example: READ_BYTES_FROM_GROUP_TRANSACTION
8779
/**
8880
* Demonstrates reading bytes values from another transaction in the same group
8981
* @param groupIndex The index of the transaction in the group to read from
@@ -94,5 +86,5 @@ export default class ScratchStorage extends Contract {
9486
public readBytesFromGroupTransaction(groupIndex: uint64, scratchSlot: uint64): bytes {
9587
return gloadBytes(groupIndex, scratchSlot)
9688
}
97-
// example: READ_BYTES_FROM_GROUP_TRANSACTION
9889
}
90+
// example: SCRATCH_STORAGE

projects/typescript-examples/contracts/artifacts/clients/ScratchStorage/ScratchStorageClient.ts

+1-1
Large diffs are not rendered by default.

projects/typescript-examples/contracts/artifacts/contracts/ScratchStorage/ScratchStorage.approval.puya.map

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"sources": [
44
"/Users/gabe.algo/Code/devportal-code-examples/projects/typescript-examples/contracts/ScratchStorage/contract.algo.ts"
55
],
6-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;AAAA;;;AAAA;;;;;;;;;;;;;;;;;AAAA;;;AAAA;;;;;;;;AAAA;;AAmEG;;AAAA;AAAA;AAAA;;AAAA;AAnEH;;;AAAA;AAAA;;;AAAA;AAmEG;;;AAAA;AAAA;AAAA;AAAA;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAbA;;AAAA;AAAA;AAAA;;AAAA;AAtDH;;;AAAA;AAAA;;;AAAA;AAsDG;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAfD;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;AAAA;;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAvCF;;AAAA;;;AAAA;;AAAA;AAAA;AAAA;;AAQ4B;AAAxB;;AACuB;AAAvB;;AACwB;AAAxB;;AACyB;;;AAAzB;;AAYe;;AACA;;AACI;;AAHJ;;AAKG;AAAX;AAAP;AAC4B;AAArB;AAAP;AACO;AAAW;AAAX;AAAP;AACkB;;;AAAX;AAAP;AAaO;AAAP;AAWF;;;AAES;;AAAA;;AAAA;AAAP;AAWF;;;AAES;;AAAA;;AAAA;AAAP",
6+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA;;AAAA;;;AAAA;;;;;;;;;;;;;;;;;AAAA;;;AAAA;;;;;;;;AAAA;;AA0DG;;AAAA;AAAA;AAAA;;AAAA;AA1DH;;;AAAA;AAAA;;;AAAA;AA0DG;;;AAAA;AAAA;AAAA;AAAA;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAXA;;AAAA;AAAA;AAAA;;AAAA;AA/CH;;;AAAA;AAAA;;;AAAA;AA+CG;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAbD;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;AAAA;;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAlCF;;AAAA;;;AAAA;;AAAA;AAAA;AAAA;;AAO4B;AAAxB;;AACuB;AAAvB;;AACwB;AAAxB;;AACyB;;;AAAzB;;AAUe;;AACA;;AACI;;AAHJ;;AAKG;AAAX;AAAP;AAC4B;AAArB;AAAP;AACO;AAAW;AAAX;AAAP;AACkB;;;AAAX;AAAP;AAWO;AAAP;AASF;;;AAES;;AAAA;;AAAA;AAAP;AASF;;;AAES;;AAAA;;AAAA;AAAP",
77
"op_pc_offset": 0,
88
"pc_events": {
99
"1": {

projects/typescript-examples/contracts/artifacts/contracts/ScratchStorage/ScratchStorage.approval.teal

+23-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
main:
66
intcblock 1 0 42 100
77
bytecblock 0x151f7c75 "Hello, Algorand!"
8-
// contracts/ScratchStorage/contract.algo.ts:26-27
8+
// contracts/ScratchStorage/contract.algo.ts:27-28
99
// @contract({ scratchSlots: [0, 1, 2, { from: 10, to: 20 }] }) // This reserves slots 0, 1, 2 and slots 10-20
1010
// export default class ScratchStorage extends Contract {
1111
txn NumAppArgs
@@ -15,28 +15,28 @@ main:
1515
match main_demonstrateScratchStorage_route@3 main_readFromGroupTransaction_route@4 main_readBytesFromGroupTransaction_route@5
1616

1717
main_after_if_else@12:
18-
// contracts/ScratchStorage/contract.algo.ts:26-27
18+
// contracts/ScratchStorage/contract.algo.ts:27-28
1919
// @contract({ scratchSlots: [0, 1, 2, { from: 10, to: 20 }] }) // This reserves slots 0, 1, 2 and slots 10-20
2020
// export default class ScratchStorage extends Contract {
2121
intc_1 // 0
2222
return
2323

2424
main_readBytesFromGroupTransaction_route@5:
25-
// contracts/ScratchStorage/contract.algo.ts:93
25+
// contracts/ScratchStorage/contract.algo.ts:85
2626
// @abimethod({ readonly: true })
2727
txn OnCompletion
2828
!
2929
assert // OnCompletion is not NoOp
3030
txn ApplicationID
3131
assert // can only call when not creating
32-
// contracts/ScratchStorage/contract.algo.ts:26-27
32+
// contracts/ScratchStorage/contract.algo.ts:27-28
3333
// @contract({ scratchSlots: [0, 1, 2, { from: 10, to: 20 }] }) // This reserves slots 0, 1, 2 and slots 10-20
3434
// export default class ScratchStorage extends Contract {
3535
txna ApplicationArgs 1
3636
btoi
3737
txna ApplicationArgs 2
3838
btoi
39-
// contracts/ScratchStorage/contract.algo.ts:93
39+
// contracts/ScratchStorage/contract.algo.ts:85
4040
// @abimethod({ readonly: true })
4141
callsub readBytesFromGroupTransaction
4242
dup
@@ -53,21 +53,21 @@ main_readBytesFromGroupTransaction_route@5:
5353
return
5454

5555
main_readFromGroupTransaction_route@4:
56-
// contracts/ScratchStorage/contract.algo.ts:80
56+
// contracts/ScratchStorage/contract.algo.ts:74
5757
// @abimethod({ readonly: true })
5858
txn OnCompletion
5959
!
6060
assert // OnCompletion is not NoOp
6161
txn ApplicationID
6262
assert // can only call when not creating
63-
// contracts/ScratchStorage/contract.algo.ts:26-27
63+
// contracts/ScratchStorage/contract.algo.ts:27-28
6464
// @contract({ scratchSlots: [0, 1, 2, { from: 10, to: 20 }] }) // This reserves slots 0, 1, 2 and slots 10-20
6565
// export default class ScratchStorage extends Contract {
6666
txna ApplicationArgs 1
6767
btoi
6868
txna ApplicationArgs 2
6969
btoi
70-
// contracts/ScratchStorage/contract.algo.ts:80
70+
// contracts/ScratchStorage/contract.algo.ts:74
7171
// @abimethod({ readonly: true })
7272
callsub readFromGroupTransaction
7373
itob
@@ -79,7 +79,7 @@ main_readFromGroupTransaction_route@4:
7979
return
8080

8181
main_demonstrateScratchStorage_route@3:
82-
// contracts/ScratchStorage/contract.algo.ts:65
82+
// contracts/ScratchStorage/contract.algo.ts:61
8383
// public demonstrateScratchStorage(): boolean {
8484
txn OnCompletion
8585
!
@@ -99,7 +99,7 @@ main_demonstrateScratchStorage_route@3:
9999
return
100100

101101
main_bare_routing@8:
102-
// contracts/ScratchStorage/contract.algo.ts:26-27
102+
// contracts/ScratchStorage/contract.algo.ts:27-28
103103
// @contract({ scratchSlots: [0, 1, 2, { from: 10, to: 20 }] }) // This reserves slots 0, 1, 2 and slots 10-20
104104
// export default class ScratchStorage extends Contract {
105105
txn OnCompletion
@@ -129,52 +129,52 @@ demonstrateScratchStorage:
129129
// Scratch.store(15, Uint64(999))
130130
pushint 999 // 999
131131
store 15
132-
// contracts/ScratchStorage/contract.algo.ts:49
132+
// contracts/ScratchStorage/contract.algo.ts:47
133133
// const value2 = Scratch.loadUint64(2)
134134
load 2
135-
// contracts/ScratchStorage/contract.algo.ts:50
135+
// contracts/ScratchStorage/contract.algo.ts:48
136136
// const value3 = Scratch.loadUint64(15)
137137
load 15
138-
// contracts/ScratchStorage/contract.algo.ts:51
138+
// contracts/ScratchStorage/contract.algo.ts:49
139139
// const bytesValue = Scratch.loadBytes(1)
140140
load 1
141-
// contracts/ScratchStorage/contract.algo.ts:48
141+
// contracts/ScratchStorage/contract.algo.ts:46
142142
// const value1 = Scratch.loadUint64(0)
143143
load 0
144-
// contracts/ScratchStorage/contract.algo.ts:53
144+
// contracts/ScratchStorage/contract.algo.ts:51
145145
// assert(value1 === 42, 'Value in slot 0 should be 42')
146146
intc_2 // 42
147147
==
148148
assert // Value in slot 0 should be 42
149-
// contracts/ScratchStorage/contract.algo.ts:54
149+
// contracts/ScratchStorage/contract.algo.ts:52
150150
// assert(bytesValue === Bytes('Hello, Algorand!'), 'Value in slot 1 should be "Hello, Algorand!"')
151151
bytec_1 // "Hello, Algorand!"
152152
==
153153
assert // Value in slot 1 should be "Hello, Algorand!"
154-
// contracts/ScratchStorage/contract.algo.ts:55
154+
// contracts/ScratchStorage/contract.algo.ts:53
155155
// assert(value2 === 100, 'Value in slot 2 should be 100')
156156
swap
157157
intc_3 // 100
158158
==
159159
assert // Value in slot 2 should be 100
160-
// contracts/ScratchStorage/contract.algo.ts:56
160+
// contracts/ScratchStorage/contract.algo.ts:54
161161
// assert(value3 === 999, 'Value in slot 15 should be 999')
162162
pushint 999 // 999
163163
==
164164
assert // Value in slot 15 should be 999
165-
// contracts/ScratchStorage/contract.algo.ts:69
165+
// contracts/ScratchStorage/contract.algo.ts:65
166166
// return true
167167
intc_0 // 1
168168
retsub
169169

170170

171171
// contracts/ScratchStorage/contract.algo.ts::ScratchStorage.readFromGroupTransaction(groupIndex: uint64, scratchSlot: uint64) -> uint64:
172172
readFromGroupTransaction:
173-
// contracts/ScratchStorage/contract.algo.ts:80-81
173+
// contracts/ScratchStorage/contract.algo.ts:74-75
174174
// @abimethod({ readonly: true })
175175
// public readFromGroupTransaction(groupIndex: uint64, scratchSlot: uint64): uint64 {
176176
proto 2 1
177-
// contracts/ScratchStorage/contract.algo.ts:82
177+
// contracts/ScratchStorage/contract.algo.ts:76
178178
// return gloadUint64(groupIndex, scratchSlot)
179179
frame_dig -2
180180
frame_dig -1
@@ -184,11 +184,11 @@ readFromGroupTransaction:
184184

185185
// contracts/ScratchStorage/contract.algo.ts::ScratchStorage.readBytesFromGroupTransaction(groupIndex: uint64, scratchSlot: uint64) -> bytes:
186186
readBytesFromGroupTransaction:
187-
// contracts/ScratchStorage/contract.algo.ts:93-94
187+
// contracts/ScratchStorage/contract.algo.ts:85-86
188188
// @abimethod({ readonly: true })
189189
// public readBytesFromGroupTransaction(groupIndex: uint64, scratchSlot: uint64): bytes {
190190
proto 2 1
191-
// contracts/ScratchStorage/contract.algo.ts:95
191+
// contracts/ScratchStorage/contract.algo.ts:87
192192
// return gloadBytes(groupIndex, scratchSlot)
193193
frame_dig -2
194194
frame_dig -1

0 commit comments

Comments
 (0)