diff --git a/tealscript_contracts/kitchen-sink-tealscript.algo.ts b/tealscript_contracts/kitchen-sink-tealscript.algo.ts index cc2d027..acb229f 100644 --- a/tealscript_contracts/kitchen-sink-tealscript.algo.ts +++ b/tealscript_contracts/kitchen-sink-tealscript.algo.ts @@ -1,70 +1,96 @@ -import { Contract } from "@algorandfoundation/tealscript"; +import { + abimethod, + Account, + Application, + assert, + assertMatch, + BigUint, + biguint, + Box, + BoxMap, + BoxRef, + bytes, + Bytes, + Contract, + Global, + GlobalState, + gtxn, + LocalState, + Txn, + Uint64, + uint64, +} from "@algorandfoundation/algorand-typescript"; +import { + DynamicArray, + UintN, +} from "@algorandfoundation/algorand-typescript/arc4"; export class KitchenSinkContract extends Contract { - globalInt = GlobalStateKey(); - globalString = GlobalStateKey({ key: "customKey" }); + globalInt = GlobalState({ initialValue: Uint64(4) }); + globalString = GlobalState({ key: "customKey" }); - localBigInt = LocalStateKey>(); + localBigInt = LocalState(); - boxOfArray = BoxKey({ key: "b" }); - boxMap = BoxMap({ prefix: "" }); - boxRef = BoxKey({ key: "FF" }); + boxOfArray = Box>>({ key: "b" }); + boxMap = BoxMap({ keyPrefix: "" }); + boxRef = BoxRef({ key: Bytes.fromHex("FF") }); useState(a: uint64, b: string, c: uint64) { this.globalInt.value *= a; - if (this.globalString.exists) { + if (this.globalString.hasValue) { this.globalString.value += b; } else { this.globalString.value = b; } - if (this.txn.sender.isOptedInToApp(this.app.id)) { - this.localBigInt(this.txn.sender).value = >(c * a); + if (Txn.sender.isOptedIn(Global.currentApplicationId)) { + this.localBigInt(Txn.sender).value = BigUint(c) * BigUint(a); } } - createApplication() { - this.globalInt.value = 4; - this.globalInt.value = this.app.id; + @abimethod({ onCreate: "require", allowActions: "NoOp" }) + createApp() { + this.globalInt.value = Global.currentApplicationId.id; } - optInToApplication() {} + @abimethod({ allowActions: ["OptIn"] }) + optIn() {} addToBox(x: uint64) { if (!this.boxOfArray.exists) { - this.boxOfArray.value = [x]; + this.boxOfArray.value = new DynamicArray(new UintN<64>(x)); } else { - this.boxOfArray.value.push(x); + this.boxOfArray.value.push(new UintN<64>(x)); } } addToBoxMap(x: string) { - this.boxMap(this.txn.sender).value = x; + this.boxMap.set(Txn.sender, Bytes(x)); } insertIntoBoxRef(content: bytes, offset: uint64, boxSize: uint64) { assert(offset + content.length < boxSize); if (this.boxRef.exists) { - this.boxRef.create(boxSize); - } else if (this.boxRef.size !== boxSize) { + this.boxRef.create({ size: boxSize }); + } else if (this.boxRef.length !== boxSize) { this.boxRef.resize(boxSize); } this.boxRef.splice(offset, offset + content.length, content); } sayHello(name: string, a: uint64): string { - return this.getHello() + name + itob(a); + return `${this.getHello()} ${name} ${Bytes(a)}`; } - checkTransaction(pay: PayTxn) { - verifyPayTxn(pay, { - amount: { greaterThan: 1000, lessThan: 2000 }, - lastValid: { greaterThan: globals.round }, - sender: this.txn.sender, - receiver: this.app.address, + checkTransaction(pay: gtxn.PaymentTxn) { + assertMatch(pay, { + amount: { between: [1000, 2000] }, + lastValid: { greaterThan: Global.round }, + sender: Txn.sender, + receiver: Global.currentApplicationId.address, }); } - private getHello(): string { + private getHello() { return "Hello"; } }