Skip to content

Instantly share code, notes, and snippets.

@jasonpaulos
Created August 18, 2020 16:23
Show Gist options
  • Save jasonpaulos/28844a66ec0aae10c3629a0fdc2ae512 to your computer and use it in GitHub Desktop.
Save jasonpaulos/28844a66ec0aae10c3629a0fdc2ae512 to your computer and use it in GitHub Desktop.
PyTeal state manipulation proposal
from pyteal import *
def approval_program():
globalStatus = Global.storage[Bytes("status")]
globalExample = Seq([
If(globalStatus.exists(),
Assert(globalStatus == Int(0)),
globalStatus.set(Int(1))
),
globalStatus.delete(),
])
senderStatus = Txn.senderStorage[Bytes("status")]
localSenderExample = Seq([
If(senderStatus.exists(),
Assert(senderStatus == Int(0)),
senderStatus.set(Int(10))
),
senderStatus.delete()
])
firstAccountStatus = Txn.accountStorage[0][Bytes("status")]
localAccountExample = Seq([
If(firstAccountStatus.exists(),
Assert(firstAccountStatus == Int(0)),
firstAccountStatus.set(Int(10))
),
firstAccountStatus.delete()
])
globalForeignStatus = Txn.foreignAppStorage[0][Bytes("status")]
globalForeignExample = Assert(And(
globalForeignStatus.exists(),
globalForeignStatus == Int(0)
))
firstAccountForeignStatus = Txn.accountStorage[0].forApp(Int(1234))[Bytes("status")]
localAccountForeignExample = Assert(And(
firstAccountForeignStatus.exists(),
firstAccountForeignStatus == Int(10)
))
program = Seq([
globalExample,
localSenderExample,
localAccountExample,
globalForeignExample,
localAccountForeignExample,
Return(Int(1))
])
return program
print(compileTeal(approval_program(), Mode.Application))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment