Skip to content

Commit

Permalink
feat: add support for emitting ARC-28 events
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx committed Mar 15, 2024
1 parent 7d3d534 commit aa4a651
Show file tree
Hide file tree
Showing 30 changed files with 1,441 additions and 96 deletions.
14 changes: 14 additions & 0 deletions examples/arc-28/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from puyapy import ARC4Contract, arc4


class Swapped(arc4.Struct):
a: arc4.UInt64
b: arc4.UInt64


class EventEmitter(ARC4Contract):
@arc4.abimethod
def emit_swapped(self, a: arc4.UInt64, b: arc4.UInt64) -> None:
arc4.emit(Swapped(b, a))
arc4.emit("Swapped(uint64,uint64)", b, a)
arc4.emit("Swapped", b, a)
82 changes: 82 additions & 0 deletions examples/arc-28/out/EventEmitter.approval.mir

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions examples/arc-28/out/EventEmitter.approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma version 10

contract.EventEmitter.approval_program:
// arc-28/contract.py:9
// class EventEmitter(ARC4Contract):
txn NumAppArgs
bz main_bare_routing@5
method "emit_swapped(uint64,uint64)void"
txna ApplicationArgs 0
match main_emit_swapped_route@2
err // reject transaction

main_emit_swapped_route@2:
// arc-28/contract.py:10
// @arc4.abimethod
txn OnCompletion
!
assert // OnCompletion is NoOp
txn ApplicationID
assert // is not creating
// arc-28/contract.py:9
// class EventEmitter(ARC4Contract):
txna ApplicationArgs 1
txna ApplicationArgs 2
// arc-28/contract.py:10
// @arc4.abimethod
callsub emit_swapped
int 1
return

main_bare_routing@5:
// arc-28/contract.py:9
// class EventEmitter(ARC4Contract):
txn OnCompletion
!
assert // reject transaction
txn ApplicationID
!
assert // is creating
int 1
return


// contract.EventEmitter.emit_swapped(a: bytes, b: bytes) -> void:
emit_swapped:
// arc-28/contract.py:10-11
// @arc4.abimethod
// def emit_swapped(self, a: arc4.UInt64, b: arc4.UInt64) -> None:
proto 2 0
// arc-28/contract.py:12
// arc4.emit(Swapped(b, a))
frame_dig -1
frame_dig -2
concat
method "Swapped(uint64,uint64)"
swap
concat
dup
log
// arc-28/contract.py:13
// arc4.emit("Swapped(uint64,uint64)", b, a)
dup
log
// arc-28/contract.py:14
// arc4.emit("Swapped", b, a)
log
retsub
58 changes: 58 additions & 0 deletions examples/arc-28/out/EventEmitter.arc32.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"hints": {
"emit_swapped(uint64,uint64)void": {
"call_config": {
"no_op": "CALL"
}
}
},
"source": {
"approval": "I3ByYWdtYSB2ZXJzaW9uIDEwCgpjb250cmFjdC5FdmVudEVtaXR0ZXIuYXBwcm92YWxfcHJvZ3JhbToKICAgIC8vIGFyYy0yOC9jb250cmFjdC5weTo5CiAgICAvLyBjbGFzcyBFdmVudEVtaXR0ZXIoQVJDNENvbnRyYWN0KToKICAgIHR4biBOdW1BcHBBcmdzCiAgICBieiBtYWluX2JhcmVfcm91dGluZ0A1CiAgICBtZXRob2QgImVtaXRfc3dhcHBlZCh1aW50NjQsdWludDY0KXZvaWQiCiAgICB0eG5hIEFwcGxpY2F0aW9uQXJncyAwCiAgICBtYXRjaCBtYWluX2VtaXRfc3dhcHBlZF9yb3V0ZUAyCiAgICBlcnIgLy8gcmVqZWN0IHRyYW5zYWN0aW9uCgptYWluX2VtaXRfc3dhcHBlZF9yb3V0ZUAyOgogICAgLy8gYXJjLTI4L2NvbnRyYWN0LnB5OjEwCiAgICAvLyBAYXJjNC5hYmltZXRob2QKICAgIHR4biBPbkNvbXBsZXRpb24KICAgICEKICAgIGFzc2VydCAvLyBPbkNvbXBsZXRpb24gaXMgTm9PcAogICAgdHhuIEFwcGxpY2F0aW9uSUQKICAgIGFzc2VydCAvLyBpcyBub3QgY3JlYXRpbmcKICAgIC8vIGFyYy0yOC9jb250cmFjdC5weTo5CiAgICAvLyBjbGFzcyBFdmVudEVtaXR0ZXIoQVJDNENvbnRyYWN0KToKICAgIHR4bmEgQXBwbGljYXRpb25B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QogICAgZHVwCiAgICBsb2cKICAgIC8vIGFyYy0yOC9jb250cmFjdC5weToxNAogICAgLy8gYXJjNC5lbWl0KCJTd2FwcGVkIiwgYiwgYSkKICAgIGxvZwogICAgcmV0c3ViCg==",
"clear": "I3ByYWdtYSB2ZXJzaW9uIDEwCgpjb250cmFjdC5FdmVudEVtaXR0ZXIuY2xlYXJfc3RhdGVfcHJvZ3JhbToKICAgIC8vIGFyYy0yOC9jb250cmFjdC5weTo5CiAgICAvLyBjbGFzcyBFdmVudEVtaXR0ZXIoQVJDNENvbnRyYWN0KToKICAgIGludCAxCiAgICByZXR1cm4K"
},
"state": {
"global": {
"num_byte_slices": 0,
"num_uints": 0
},
"local": {
"num_byte_slices": 0,
"num_uints": 0
}
},
"schema": {
"global": {
"declared": {},
"reserved": {}
},
"local": {
"declared": {},
"reserved": {}
}
},
"contract": {
"name": "EventEmitter",
"methods": [
{
"name": "emit_swapped",
"args": [
{
"type": "uint64",
"name": "a"
},
{
"type": "uint64",
"name": "b"
}
],
"returns": {
"type": "void"
}
}
],
"networks": {}
},
"bare_call_config": {
"no_op": "CREATE"
}
}
9 changes: 9 additions & 0 deletions examples/arc-28/out/EventEmitter.clear.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Op // Stack (out) Source code Source line

#pragma version 10

// contract.EventEmitter.clear_state_program() -> uint64:
main_block@0:
int 1 // 1 class EventEmitter(ARC4Contract): arc-28/contract.py:9
return // class EventEmitter(ARC4Contract): arc-28/contract.py:9

7 changes: 7 additions & 0 deletions examples/arc-28/out/EventEmitter.clear.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma version 10

contract.EventEmitter.clear_state_program:
// arc-28/contract.py:9
// class EventEmitter(ARC4Contract):
int 1
return
41 changes: 41 additions & 0 deletions examples/arc-28/out/EventEmitter.destructured.ir

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions examples/arc-28/out/EventEmitter.ssa.ir

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions examples/arc-28/out/EventEmitter.ssa.opt_pass_1.ir

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions examples/arc-28/out/EventEmitter.ssa.opt_pass_2.ir

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions examples/arc-28/out/client_EventEmitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is auto-generated, do not modify
# flake8: noqa
# fmt: off
import typing

import puyapy


class EventEmitter(puyapy.arc4.ARC4Client, typing.Protocol):
@puyapy.arc4.abimethod
def emit_swapped(
self,
a: puyapy.arc4.UInt64,
b: puyapy.arc4.UInt64,
) -> None: ...
14 changes: 14 additions & 0 deletions examples/arc-28/out/contract.awst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aa4a651

Please sign in to comment.